【发布时间】:2013-06-16 02:44:02
【问题描述】:
我从 3.2.2 升级到 rails4,现在我从我的 rabl 模板中获得了这个未定义的方法,该方法 id 在升级之前没有获得。 程序上的“tooth”参数是由 getter/setter 方法设置的,它作为名为 properties 的 hstore 哈希存储在 postgres 数据库中。 不知道 rails4 发生了什么变化来实现这一点! 任何帮助将不胜感激。
错误:
Showing /home/action/app/views/procedures/chart.json.rabl where line #1 raised:
undefined method `scan' for {"tooth"=>""}:Hash
Extracted source (around line #1):
1 object @procedures
2 attributes :buccal, :mesial, :occlusal, :distal, :lingual
Trace of template inclusion: app/views/procedures/_procedures_table.html.erb, app/views/procedures/chart.html.erb
程序模型(:tooth 的 getter 和 setter 方法)
%w[tooth buccal mesial occlusal distal lingual].each do |key|
attr_accessible key
scope "has_#{key}", lambda { |value| where("properties @> (? => ?)", key, value) }
define_method(key) do
properties && properties[key]
end
define_method("#{key}=") do |value|
self.properties = (properties || {}).merge(key => value)
end
end
宝石文件:
source 'http://rubygems.org'
gem 'rails', '4.0.0.rc2'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem "paperclip", "~> 3.0"
gem 'rabl'
gem 'activerecord-postgres-hstore'
gem "bugsnag"
gem 'country_select'
gem 'bullet', group: :development
# Asset template engines
gem 'sass-rails', '~> 4.0.0.rc1'
gem 'coffee-rails', '~> 4.0.0.rc1'
gem 'uglifier', '>= 1.3.0'
gem 'twitter-bootstrap-rails'
gem 'therubyracer', :platform => :ruby
gem 'less-rails'
gem 'jquery-ui-rails'
gem 'jquery-rails'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
# Declarative Authorization
gem 'declarative_authorization'
gem 'protected_attributes'
# Authlogic
gem 'authlogic'
gem 'simple_form', '3.0.0.rc'
group :production do
end
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
gem 'rubber'
gem 'open4'
gem 'gelf'
gem 'graylog2_exceptions', :git => 'git://github.com/wr0ngway/graylog2_exceptions.git'
gem 'graylog2-resque'
【问题讨论】:
-
找到答案了!! Rails 4 现在有对 Hstore 的原生支持,这很棒,但我没有意识到。为了解决我的问题,我只是按照下面的指南进行操作,该指南非常适合使用 hstore 设置我的模型,然后删除了我的 getter/setter 方法。 blog.remarkablelabs.com/2012/12/…
-
以防万一,我将我的应用程序迁移到 Rails 4 Rc2 并且我遇到了与“扫描”相关的相同问题,但我只需要从模型中删除序列化方法 :-)。序列化 :data, ActiveRecord::Coders::Hstore
标签: ruby-on-rails ruby-on-rails-4 rabl