Jonathan Gill
2009-Aug-05 17:39 UTC
how do you access params that are both model based and non model based?
Hi all Ive got a form thats based on a model that I need to put a drop down box and additional text field to build the description for the item. heres some quick code View <%= form_for (@shape) do |f| %> <%= f.text_field :description %> <%= select_tag "shape_name", "<option>round</option><option>square</ option><option>triangular</option>" %> <%= text_field_tag "shape_code" => Controller @shape.new @shape.description = params[:description] @shape.shape = "#{params[:shape_name]} #{params[:shape_code]}" @shape.save What happens is I get the shape.shape set right (to the name from the select box and the code from the text field) but description is always empty, Heres whats in the params when I do a raise shape.to_yaml to debug it. {"shape_name"=>"triangular", "shape_code"=>"shape code is here", "order"=>{"description"=>"this is a description"} "shape_code"=>"342", "shape_number"=>"111", "finish1"=>"Silver", "commit"=>"Create", Can someone point out how I should be accessing the params so I can set the description of the shape? Many thanks Jonathan Gill
Jonathan Gill
2009-Aug-05 19:30 UTC
how do you access params that are both model based and non model based?
Hi all Apologies first of all if this it the third time of seeing this, I posted previously but didn''t see it on the googlegroup archive or current discussions. Ive got a form that''s based on a model that I need to put a drop down box and additional text field to build the description for the item. heres some quick code View <%= form_for (@shape) do |f| %> <%= f.text_field :description %> <%= select_tag "shape_name", "<option>round</option><option>square</ option><option>triangular</option>" %> <%= text_field_tag "shape_code" => Controller @shape.new @shape.description = params[:description] @shape.shape = "#{params[:shape_name]} #{params[:shape_code]}" @shape.save What happens is I get the shape.shape set right (to the name from the select box and the code from the text field) but description is always empty, Heres whats in the params when I do a raise shape.to_yaml to debug it. {"shape_name"=>"triangular", "shape_code"=>"shape code is here", "order"=>{"description"=>"this is a description"}} Can someone point out how I should be accessing the params so I can set the description of the shape? Many thanks Jonathan Gill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ilan Berci
2009-Aug-05 19:54 UTC
Re: how do you access params that are both model based and non model based?
Jonathan Gill wrote:> > {"shape_name"=>"triangular", > "shape_code"=>"shape code is here", > "order"=>{"description"=>"this is a description"}} > > Can someone point out how I should be accessing the params so I can > set the description of the shape? > > Many thanks > > Jonathan Gill@shape.description = params[:order][:description] -- Posted via http://www.ruby-forum.com/.
Jonathan Gill
2009-Aug-05 20:44 UTC
Re: how do you access params that are both model based and non model based?
Many thanks for that! Just what I needed to know. I thought I tried that, but I guess I didnt. Along the same lines how about when Ive got a select_date on the form? The data comes back in the params as {stuff => "something", order=> {"thedate(3i)" =>"2009", "thedate(2i)" => "10", "thedate(1i)" => "1"}} Ive tried param[:order][:thedate](3i) and params[:order][:thedate(3i)] and a load of other ways that are definately wrong! Ive also looked through the ruby book and the agile ruby on rails book, but not sure what to look for so cant help myself here. Can someone point me in the right direction? Many thanks Jonathan Gill On Wed, Aug 5, 2009 at 8:54 PM, Ilan Berci <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Jonathan Gill wrote: > > > > {"shape_name"=>"triangular", > > "shape_code"=>"shape code is here", > > "order"=>{"description"=>"this is a description"}} > > > > Can someone point out how I should be accessing the params so I can > > set the description of the shape? > > > > Many thanks > > > > Jonathan Gill > > @shape.description = params[:order][:description] > -- > 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 -~----------~----~----~----~------~----~------~--~---
Jonathan Gill
2009-Aug-05 21:36 UTC
Re: how do you access params that are both model based and non model based?
To post a followup. So the archive is here. Seems the problem is when not doing mass assignment active record does the date object creation. This blog post http://blog.springenwerk.com/2008/05/set-date-attribute-from-dateselect.htmlexplains is much better than I can but lets say it solves it. So updating a date or datetime field in a model from params yourself is not easy but can be done with the above link (thats for the search next time!) Thanks to all that helped on this. Jonathan Gill On Wed, Aug 5, 2009 at 9:44 PM, Jonathan Gill <jgill72-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>wrote:> Many thanks for that! Just what I needed to know. I thought I tried that, > but I guess I didnt. > > Along the same lines how about when Ive got a select_date on the form? The > data comes back in the params as > {stuff => "something", > order=> {"thedate(3i)" =>"2009", > "thedate(2i)" => "10", > "thedate(1i)" => "1"}} > > Ive tried > > param[:order][:thedate](3i) > and > params[:order][:thedate(3i)] > > and a load of other ways that are definately wrong! Ive also looked > through the ruby book and the agile ruby on rails book, but not sure what to > look for so cant help myself here. > > Can someone point me in the right direction? > > Many thanks > > Jonathan Gill > > > On Wed, Aug 5, 2009 at 8:54 PM, Ilan Berci < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> >> Jonathan Gill wrote: >> > >> > {"shape_name"=>"triangular", >> > "shape_code"=>"shape code is here", >> > "order"=>{"description"=>"this is a description"}} >> > >> > Can someone point out how I should be accessing the params so I can >> > set the description of the shape? >> > >> > Many thanks >> > >> > Jonathan Gill >> >> @shape.description = params[:order][:description] >> -- >> 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 -~----------~----~----~----~------~----~------~--~---
Hi all, I have two fields in a form. One text field non asociated to the model for the user type a value. the view is: <%= text_field_tag ''item_cod'','''', :size => 3 %> Other a field with a select list with codes, names for the user select from. The view is: <%= f.select :item_id, Item.select_list, :size => 40 %> item_id is the real field of my model. I want the following behavior. 1. If the user type a code into the text_field tag -> Update the list so the user view the corresponding name of the item they type. 2. If the user select from the list -> Update the text field with the code corresponding to the name selected. (this is the easy part) My form works fine with one Observe field for the :item_id list but I can''t do work the point 1. Thanks in advance, FF I want the>
Please don''t hijack threads. It will hide your problem, and will not endear you to folks on most mailing lists, including this one. Best regards, Bill On Wed, 2009-08-05 at 19:05 -0300, Fabian wrote:> Hi all, > I have two fields in a form. > One text field non asociated to the model for the user type a value. the > view is: > <%= text_field_tag ''item_cod'','''', :size => 3 %> > > Other a field with a select list with codes, names for the user select > from. The view is: > > <%= f.select :item_id, Item.select_list, :size => 40 %> > > item_id is the real field of my model. > > I want the following behavior. > 1. If the user type a code into the text_field tag -> Update the list so > the user view the corresponding name of the item they type. > 2. If the user select from the list -> Update the text field with the > code corresponding to the name selected. (this is the easy part) > > My form works fine with one Observe field for the :item_id list but I > can''t do work the point 1. > > Thanks in advance, > FF > > > I want the > > > > > >
Michael Guterl
2009-Aug-06 03:25 UTC
Re: how do you access params that are both model based and non model based?
Jonathan Gill wrote:> Hi all > > Ive got a form thats based on a model that I need to put a drop down > box and additional text field to build the description for the item. > > heres some quick code > > View > > <%= form_for (@shape) do |f| %> > <%= f.text_field :description %> > <%= select_tag "shape_name", "<option>round</option><option>square</ > option><option>triangular</option>" %> > <%= text_field_tag "shape_code" => > > > Controller > > @shape.new > @shape.description = params[:description] > @shape.shape = "#{params[:shape_name]} #{params[:shape_code]}" > @shape.save > > What happens is I get the shape.shape set right (to the name from the > select box and the code from the text field) but description is always > empty, > > Heres whats in the params when I do a raise shape.to_yaml to debug it. > > {"shape_name"=>"triangular", > "shape_code"=>"shape code is here", > "order"=>{"description"=>"this is a description"} > "shape_code"=>"342", > "shape_number"=>"111", > "finish1"=>"Silver", > "commit"=>"Create", > > > Can someone point out how I should be accessing the params so I can > set the description of the shape? >Because you''re using form_for it prefixes the form element names with the model name. Which in your case must not be Shape, but Order, seeing that params[:order][:description] contains the description. That is how you access the value by the way: params[:order][:description] Honestly though, I''m really not sure why the description is going into params[:order], is Order really the model name? I''m going to assume so... Here''s a brief, potentially correct explanation of how this all works. <input name="order[description]" ... /> This gets pulled into the params hash as params[:shape][:description]. Following this naming convention for your form items (or using f.select and f.text_field with form_for) will give you the ability to use this syntax: @order = Order.new(params[:order]) @order.save Best, Michael Guterl -- Posted via http://www.ruby-forum.com/.