I hope raising exceptions on unknown attributes is/stays expected behavior. I know it has saved me debugging time when I have had typos in my field names.

It is easy to create sub-hashes from your views so you only include the attributes you wish:

<input name="foo_bar[name]"/>
<input name="foo_bar[sitter]"/>
<input name="children"/>

Then your params will look like:

{:children => 'foo', :foo_bar => {:name => 'bob', :sitter => 'dog'}}

So you create your new record like:

FooBar.new params[:foo_bar]

-Sean

On Nov 29, 2005, at 3:38 PM, Charles Dupont wrote:

Charles Dupont wrote:
Problem:
params = {:name => 'bob', :sitter => 'dog', children => 'foo'}
correction:
  params = {:name => 'bob', :sitter => 'dog', :children => 'foo'}

ActiveRecord model 'FooBar' with columns named 'name', 'sitter', 'houseboat'.
If I do
boo = FooBar.new(params)
I get a error stating that method 'children=' does not exist for class FooBar. I think it would make more sense if the items in the hash with keys that are not attributes of the model should be dropped without an error. I have a solution for this but I wanted to make sure that this is incorrect behavior for this method before I spend time fixing it.
Charles


--
Charles Dupont  Computer System Analyst         School of Medicine
                Department of Biostatistics     Vanderbilt University
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to