Rails Gem访问模型columns_hash?

时间:2018-03-18 23:27:00

标签: ruby-on-rails postgresql

我正在尝试更新https://github.com/ledermann/rails-settings/pull/84/files,以便它可以选择使用json / jsonb列类型(这样可以更好地查询)

当我注释serialize :value, Hash时,一切正常,因为rails / postgres正在处理序列化。

我尝试使用columns_hash对象查看列类型,为此Gem添加配置。

class Settings
  #... more
  if self.columns_hash['value'].type.to_sym == :text
    serialize :value, Hash
  end
end

在服务器启动时,我收到错误连接错误

There was an error while trying to load the gem 'my-rails-settings'. (Bundler::GemRequireError)
Gem Load Error is: No connection pool for MyRailsSettings
Backtrace for gem load error is:
/Users/blairanderson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:570:in `retrieve_connection'
/Users/blairanderson/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:113:in `retrieve_connection'

full stack trace

哪种方式有意义,因为它基本上在服务器启动时发出数据库请求...还有其他方法可以实现同样的功能而无需用户设置配置吗?

0 个答案:

没有答案