Undefined `scan 'method for {" tooth "=>" "}: Hash
I upgraded to rails4 from 3.2.2, and now I got this undefined method from my rabl template, which id did not get before the update. the βtoothβ parameter in procedures is a setter / setter method, which is stored in the postgres database as a hash hash with property names. Not sure what has changed in rails4 to make this happen! Any help would be greatly appreciated.
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 Procedure model (getter and setter method for: tooth)
%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' Found the answer !! Rails 4 now has built-in support for Hstore, which is awesome, but I didn't get it. To fix my problem, I just followed this tutorial, which is great for setting up my model with hstore, and then removed my getter / setter methods. http://blog.remarkablelabs.com/2012/12/a-love-affair-with-postgresql-rails-4-countdown-to-2013