Reputation: 3869
I have a model like this:
class Attribute < ActiveRecord::Base
attr_accessible :name
end
and parameters in post action:
name='foo' (not attribute[name])
In Create action I can to create Attribute like this:
attribute=Attribute.new(:name => params[:name])
How tell rails parse every parameter like the model attribute?
attribute=Attribute.new(params[:attribute])
Upvotes: 0
Views: 135
Reputation: 9623
Assuming you can't fix the form to submit the param in the conventional way, you can do this in your controller by editing params before creation:
params[:attribute][:name] = params[:name]
attribute=Attribute.new(params[:attribute])
or if you had a lot of params all of which you want in attribute you could just use:
attribute=Attribute.new(Hash.new(:attribute => params))
Upvotes: 1