ruby on rails - Undefined method in migration while trying to massage data -
rails 3. here code:
class addforautocompleteinshops < activerecord::migration def add_column :shops, :for_autocomplete, :string end shop.reset_column_information shops = shop.all shops.each |shop| shop.for_autocomplete = %(#{shop.name} #{shop.formatted_address}) shop.save end def downwards remove_column :shops, :for_autocomplete end end error message occurred:
rake aborted! error has occurred, later migrations canceled: undefined method `for_autocomplete=' #<shop:0x007fba66be7af8> /users/abc/sites/test/db/migrate/20130219121256_add_for_autocomplete_in_shops.rb:11:in `block in <class:addforautocompleteinshops>' /users/abc/sites/test/db/migrate/20130219121256_add_for_autocomplete_in_shops.rb:10:in `each' /users/abc/sites/test/db/migrate/20130219121256_add_for_autocomplete_in_shops.rb:10:in `<class:addforautocompleteinshops>' /users/abc/sites/test/db/migrate/20130219121256_add_for_autocomplete_in_shops.rb:1:in `<top (required)>' tasks: top => db:migrate (see total trace running task --trace) what's wrong code? tested in rails console works fine.
thanks.
your code should part of either up or down methods - not in middle of migration class.
ruby-on-rails
No comments:
Post a Comment