Newbie: Help Please - Model Validation Error

Hi,

I’d be grateful for your help.

I get the error (see below) everytime I add the
following into a newly generated (via scaffold) model
class:

validates_presence_of :myname, :mymessage, :mytel

Without it, I can insert records into my database.
With it, I get the error :frowning:

ERROR>>

ArgumentError in AdminController#create

wrong number of arguments (1 for 0)

RAILS_ROOT: script/…/config/…

Application Trace | Framework Trace | Full Trace
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/callbacks.rb:308:in
callback' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/callbacks.rb:308:invalid?’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/validations.rb:723:in
save_without_transactions' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/transactions.rb:126:insave’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/connection_adapters/abstract/database_statements.rb:51:in
transaction' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/transactions.rb:91:intransaction’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/transactions.rb:118:in
transaction' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/transactions.rb:126:insave’
#{RAILS_ROOT}/app/controllers/admin_controller.rb:25:in
`create’

Request

Parameters: {“commit”=>“Create”,
“enquiry”=>{“date_time(1i)”=>“2006”,
“date_time(2i)”=>“6”, “date_time(3i)”=>“30”,
“date_time(4i)”=>“00”, “date_time(5i)”=>“13”,
“mytel”=>“1”, “callback”=>“0”, “myname”=>“1”,
“mymessage”=>“1”}}

Show session dump

Response

Headers: {“cookie”=>[], “Cache-Control”=>“no-cache”}


Copy addresses and emails from any email account to Yahoo! Mail - quick,
easy and free. http://uk.docs.yahoo.com/trueswitch2.html

validates_presence_of :myname, :mymessage, :mytel

Have you tried putting those on their own lines?

validates_presence_of :myname
validates_presence_of :mymessage
validates_presence_of :mytel

?

think of validates_presence_of like a javascript function, you’re
passing vars to it in a specific order.

validates_presence_of(object,optionalthingslikemessageandifblocks)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs