1

In user model I've got attribute location of type point. Now I've got a validation code:

validates :location, :format => { :with => /\(-?\d+(?:\.\d+)?,-?\d(?:\.\d+)?\)/,
                                    :on => :update,
                                    :if => :location_changed? }

It works fine in console, on localhost, but on heroku it returns:

Processing by UsersController#update as / 2012-07-31T18:14:37+00:00 app[web.1]: Parameters: {"user"=>{"location"=>"(3.545452,2.4353534)"}, "id"=>"self"} 2012-07-31T18:14:37+00:00 app[web.1]: Completed 500 Internal Server Error in 13ms 2012-07-31T18:14:37+00:00 app[web.1]: 2012-07-31T18:14:37+00:00 app[web.1]: NoMethodError (undefined method location_changed?' for #<User:0x00000004dc29c8>): 2012-07-31T18:14:37+00:00 app[web.1]:
app/controllers/users_controller.rb:16:in
update'

Actually it works also great in heroku console, but don't work in curl request.

Rails version 3.2.7.

attr_accessible :profile_picture, :password, :location

Thanks!

Ivan Kozlov
  • 561
  • 2
  • 8
  • 19
  • it might help showing the code of your model... – phoet Jul 31 '12 at 18:27
  • A huge amount of code in a model. Which part do you need? – Ivan Kozlov Jul 31 '12 at 18:39
  • the part with the method that is missing? – phoet Jul 31 '12 at 18:54
  • 1
    Its a standart rails helper, aka attr_changed?. So i haven't got any code, which relates with this part of validation. The main problem, that it works fine on a local machine. – Ivan Kozlov Jul 31 '12 at 19:05
  • what do you mean by "standart rails helper" ? something in ```app/helpers```? in this case you will need to ```include``` it into your model in any environment that does no live class-reloading! – phoet Jul 31 '12 at 19:29
  • its a part of rails api; standard method like .nil? .blank? etc. – Ivan Kozlov Jul 31 '12 at 19:31
  • i've never seen ```location_changed?``` in any rails documentation. could you provide a link to it? – phoet Jul 31 '12 at 19:36
  • OK, http://stackoverflow.com/questions/5051135/rails-3-check-if-attribute-changed – Ivan Kozlov Jul 31 '12 at 19:45
  • http://ar.rubyonrails.org/classes/ActiveRecord/Dirty.html – Ivan Kozlov Jul 31 '12 at 19:46
  • what?!?! i think you are not getting anything! i want to see the code of the method that you are referencing to in your validation and that rails complains about and it's name is ```location_changed?``` this is not part of any rails api. it's a custom method that you are implementing in your model. – phoet Jul 31 '12 at 19:49
  • 1
    It looks like you're joking! ActiveModel::Dirty - includes in a default rails build, i can use these methods in any model. For example MyModel.changed? ; MyModel.some_attr_changed? etc.. I don't need to implement them by myself. They already exist and goes out of the box=) lol if you don't understand it. Thanks for help. – Ivan Kozlov Jul 31 '12 at 20:01
  • sorry, you are right, i did not know of this little magic-helper! – phoet Jul 31 '12 at 20:24

1 Answers1

0

It looks like a magic. I fixed it with recreation if table and server restart. Very strange.

Ivan Kozlov
  • 561
  • 2
  • 8
  • 19