I have a controller which is passed params[:transfer] from a form. I want to add some key vale pairs so the .create(params[:transfer] used later has the other data base columns not populated in the form. thanks reg -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Reg Phipps wrote:> I have a controller which is passed params[:transfer] from a form. I > want to add some key vale pairs so the .create(params[:transfer] used > later has the other data base columns not populated in the form. > > thanks > regIf I understand the question right, you want to add to the params{:transfer] hash so you can use/modify it later, possibly during a create. One possibility is that if you are not using it right away is to just store it in your session: session[:transfer] = params[:transfer] session[:transfer] [new_key]= new_val # then add vals to it as required then later on within the session.. SomeModel.create(session[:transfer]) hope this helps ilan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> I have a controller which is passed params[:transfer] from a form. I > want to add some key vale pairs so the .create(params[:transfer] used > later has the other data base columns not populated in the form.Foo.create( {:foo => ''bar'', :one => 2}.merge(params[:transfer]) ) This way you can set *all* the defaults and anything specified in params[:transfer] will over write them... -philip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom wrote:>> I have a controller which is passed params[:transfer] from a form. I >> want to add some key vale pairs so the .create(params[:transfer] used >> later has the other data base columns not populated in the form. > > Foo.create( {:foo => ''bar'', :one => 2}.merge(params[:transfer]) ) > > This way you can set *all* the defaults and anything specified in > params[:transfer] will over write them... > > -philipThanks, I''ll try it out and let you know. Another option may be to set the other fields (which have fixed values) through the view by using MagicFieldNames http://wiki.rubyonrails.org/rails/pages/MagicFieldNames Does that make sense ? reg -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Reg Phipps wrote:> Philip Hallstrom wrote: >>> I have a controller which is passed params[:transfer] from a form. I >>> want to add some key vale pairs so the .create(params[:transfer] used >>> later has the other data base columns not populated in the form. >> >> Foo.create( {:foo => ''bar'', :one => 2}.merge(params[:transfer]) ) >> >> This way you can set *all* the defaults and anything specified in >> params[:transfer] will over write them... >> >> -philip > > Thanks, I''ll try it out and let you know. > > Another option may be to set the other fields (which have fixed values) > through the view by using MagicFieldNames > http://wiki.rubyonrails.org/rails/pages/MagicFieldNames > > Does that make sense ? > > regphilip, sorry I don''t quite understand. Is Foo the hash? with two key value pairs where key is :foo and value is ''bar'' key is :one and valie is ''2'' and this is then merged with params[:transfer] Don''t I need to declare Foo ? reg -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Reg Phipps wrote:> Reg Phipps wrote: >> Philip Hallstrom wrote: >>>> I have a controller which is passed params[:transfer] from a form. I >>>> want to add some key vale pairs so the .create(params[:transfer] used >>>> later has the other data base columns not populated in the form. >>> >>> Foo.create( {:foo => ''bar'', :one => 2}.merge(params[:transfer]) ) >>> >>> This way you can set *all* the defaults and anything specified in >>> params[:transfer] will over write them... >>> >>> -philip >> >> Thanks, I''ll try it out and let you know. >> >> Another option may be to set the other fields (which have fixed values) >> through the view by using MagicFieldNames >> http://wiki.rubyonrails.org/rails/pages/MagicFieldNames >> >> Does that make sense ? >> >> reg > > philip, sorry I don''t quite understand. Is Foo the hash? with two key > value pairs where > key is :foo and value is ''bar'' > key is :one and valie is ''2'' > and this is then merged with params[:transfer] > > Don''t I need to declare Foo ? > > regGot it ! I used foo = {:status => ''pending'', :initiation_method => ''user''} params[:transfer].update(foo) ... ... .create(params[:transfer]) The table is now created with the other columns reg -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Reg Phipps wrote: >> Philip Hallstrom wrote: >>>> I have a controller which is passed params[:transfer] from a form. I >>>> want to add some key vale pairs so the .create(params[:transfer] used >>>> later has the other data base columns not populated in the form. >>> >>> Foo.create( {:foo => ''bar'', :one => 2}.merge(params[:transfer]) ) >>> >>> This way you can set *all* the defaults and anything specified in >>> params[:transfer] will over write them... >>> >>> -philip >> >> Thanks, I''ll try it out and let you know. >> >> Another option may be to set the other fields (which have fixed values) >> through the view by using MagicFieldNames >> http://wiki.rubyonrails.org/rails/pages/MagicFieldNames >> >> Does that make sense ? >> >> reg > > philip, sorry I don''t quite understand. Is Foo the hash? with two key > value pairs where > key is :foo and value is ''bar'' > key is :one and valie is ''2'' > and this is then merged with params[:transfer] > > Don''t I need to declare Foo ?I used Foo to represent whatever your model is. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---