Topic: validates_presence_of(name, :message => "message") fails

validates_presence_of(name, :message => "message") fails while
validates_presence_of:name works. whats the difference. radrails did an auto complete and i got the first syntax while second one was on the mac tutorial site.

please clarify. also is there a API somewhere i can look at?

Re: validates_presence_of(name, :message => "message") fails

You can see the documentation for validates_presence_of at: … resence_of

I'm not sure why the first one is failing.  Can you tell us what error it's giving you?

Re: validates_presence_of(name, :message => "message") fails

sorry its this which works


validates_numericality_of(budget, :message => "message")

this fails

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1129:in `method_missing'
#{RAILS_ROOT}/app/controllers/expenses_controller.rb:12:in `list'

Last edited by abby (2006-11-19 03:07:52)

Re: validates_presence_of(name, :message => "message") fails

you need to do

validates_numericality_of(:budget, :message=> "message")
# OR
validates_numericality_of :budget, :message => "message"

if you do
validates_numericality_of(budget, :message=> "message")

you're trying to pass it a variable named budget... instead of the symbol :budget

Last edited by pjleonhardt (2006-11-19 04:04:52)

Re: validates_presence_of(name, :message => "message") fails

thanks a lot. why does it work for name though??

Re: validates_presence_of(name, :message => "message") fails

because there's a method called 'name' that exists in your controller.  If you were to use it you'd find that it has a value of 'MyController' or whatever controller you're using.
In other words it's a coincidence that you've used an object that's already in use, so it didn't give you an error about an unknown object.