Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `scan' for {"tooth"=>""}:Hash

I upgraded to rails4 from 3.2.2 and i now get this undefined method from my rabl template that id didn't get before the upgrade. the "tooth" paramater on procedures is a set by a getter/setter method that is stored in the postgres database as a hstore hash named properties. Not sure what has changed in rails4 to make this happen! Any help would be much 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

Procedures 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'
like image 468
mattclar Avatar asked Jun 16 '13 02:06

mattclar


1 Answers

Found the answer!! Rails 4 now has native support for Hstore, which is awesome but I hadn't realised. To fix my problem i merely followed this guide below which is great to set up my model with hstore and then deleted my getter/setter methods. http://blog.remarkablelabs.com/2012/12/a-love-affair-with-postgresql-rails-4-countdown-to-2013

like image 60
mattclar Avatar answered Sep 29 '22 05:09

mattclar