Al11
(Al)
December 18, 2009, 11:45pm
1
Anyone experience this before?
I have a very simple form, and when I try to submit the form I get an
"unknown attribute: commit" error.
Here is the form:
<% form_for @nominator do |f| %>
<%= f.error_messages %>
<%= f.label :first_name %>
<%= f.text_field :first_name %>
<%= f.label :last_name %>
<%= f.text_field :last_name %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.submit "Register" %>
<% end %>
And parameters fed:
Parameters:
{"commit"=>"Register",
"nominator"=>{"last_name"=>"Smith",
"first_name"=>"Barney",
"email"=>"nominator@email.com"}}
Here's my model in nominator.rb:
class Nominator < ActiveRecord::Base
acts_as_authentic
has_many :students
validates_presence_of :email
end
Btw, I'm using authlogic, although I don't suspect that has anything
to do with this error, as I've commented out the "acts_as_authentic"
and still get the same error. Thanks in advance, folks.
-Sal
Anyone experience this before?
I have a very simple form, and when I try to submit the form I get an
"unknown attribute: commit" error.
Here is the form:
<% form_for @nominator do |f| %>
<%= f.error_messages %>
<%= f.label :first_name %>
<%= f.text_field :first_name %>
<%= f.label :last_name %>
<%= f.text_field :last_name %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.submit "Register" %>
Get rid of f.submit and use submit_tag. That will keep the 'commit' parameter from being included in params[:nominator].
Well you don't show your controller code, which I suspect is the culprit.
For example I suspect that you are doing something like
Nominator.create(params)
or
@nominator.update_attributes (params)
instead of
Nominator.create(params['nominator'])
or
@nominator.update_attributes (params['nominator'])
or the like in your create and or update actions.
Note those parameters
{"commit"=>"Register",
"nominator"=>{
"last_name"=>"Smith",
"first_name"=>"Barney",
"email"=>"nominator@email.com"
}
}
Not all of the parameters are model attributes. The commit parameter
is telling you which button was pushed. It's usually ignored since
there is only one, but ...
Al11
(Al)
December 19, 2009, 3:53pm
4
Rick,
You hit the nail right on the head! In my controller, I had the
following:
@nominator = Nominator.new(params)
When I changed it to
@nominator = Nominator.new(params['nominator'])
that cleared it up!
Thanks!
-Sal