未定义的方法`scan'for {“tooth”=>“”}:哈希

时间:2013-06-16 02:44:02

标签: ruby-on-rails ruby-on-rails-4 rabl

我从3.2.2升级到rails4,我现在从我的rabl模板中获取这个未定义的方法,该模板在升级之前没有得到id。 过程中的“牙齿”参数是由getter / setter方法设置的,该方法作为名为属性的hstore散列存储在postgres数据库中。 不确定rails4中发生了什么变化才能实现这一目标! 任何帮助将不胜感激。

ERROR:

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

程序模型(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

的Gemfile:

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'

1 个答案:

答案 0 :(得分:5)

找到答案!! Rails 4现在支持Hstore,这很棒,但我还没有意识到。为了解决我的问题,我只是按照下面的指南,这很好用hstore设置我的模型,然后删除我的getter / setter方法。 http://blog.remarkablelabs.com/2012/12/a-love-affair-with-postgresql-rails-4-countdown-to-2013