我有一个gem,我想生成一个qrcode,如果配置启用了active_storage
app/config/initializers/cryptocoin_payable.rb
CryptocoinPayable.configure do |config|
config.qrcode = :active_storage
end
个字符
它没有工作,因为
CryptoCoinPayable::Configuration is nil
型
我试着把它放在初始化之后
module CryptocoinPayable
end
if defined?(Rails)
module CryptocoinPayable
class Railtie < Rails::Railtie
initializer 'cryptocoin_payable.active_storage' do
ActiveSupport.on_load(:after_initialize) do
require 'cryptocoin_payable/coin_payment'
if (CryptocoinPayable.configuration == :qrcode)
CryptocoinPayable::CoinPayment.has_one_attached(:qrcode)
end
end
end
rake_tasks do
path = File.expand_path(__dir__)
Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
end
end
end
end
require 'cryptocoin_payable/config'
require 'cryptocoin_payable/errors'
require 'cryptocoin_payable/version'
require 'cryptocoin_payable/adapters'
型
但它不工作“qrcode”是未定义的方法
如何根据配置设置has_*one_*attached
?
下面是响应:https://github.com/sbounmy/cryptocoin_payable
1条答案
按热度按时间s1ag04yj1#
所以解决方案是:
请确保我们正确初始化
after
active_storage被反映。https://github.com/rails/rails/blob/9064735ec5cd3c679f8ffabc42532dd85223af58/activestorage/lib/active_storage/engine.rb#L171(如果你尝试后,附加它会引发一个不支持的宏错误)字符串
还确保rspec确实拿起railtie在我的情况下,我不得不要求'rails'在我的spec_helper之前cryptocoin_payable(定义?(Rails))