ruby on rails - Affecting resulting params set from form_for -
relative newbie here ruby on rails.
using standard form_for
method in view someobjcontroller#new
action
= form_for @someobj |f| . . . %p.submits = f.submit "submit", :class => "submit"
a submission param[]
array produced contains hash of @someobj
fields set in form, such
param[someobj] => { "field1" => "val1", "field2" => "val2", ... }
i prefer put different value, result of someobj.to_s
param[someobj]
someobjcontroller#create
work with, such that
param[someobj] => "strvalfromtos"
i doubt it's relative, in case, model underlying #new
action not persistent in database (i.e., someobj
not derived activerecord::base
, though portions of activemodel included.)
i haven't had luck trying adjust until after #create invoked, submission #new #create want amend. it's not clear me if should focusing more on form_for
statement or doing special in controller (i'm guessing form_for
right focus).
and, yes, whole thing bit ocd of me, actual fieldnames long (appropriately model) data needed #create small.
is there relatively painless way this, assuming someobj.to_s
has been written?
many thanks, richard
change
when submit form, controller receive params hash, you've stated (rails params explained?)
that means can change value in hash wish:
def create #has access params hash params[:owner][:key] = value end
as create
method receives hash object, you'll have change in here. because it's standard hash (which has been declared), should able alter required
add
if want add values params hash, can use .merge
method, this:
def create #has access params hash params[:key].merge(user_id: current_user.id) end
Comments
Post a Comment