OK. This is embarrassing. I need to programatically set the value of a field on a form (I get the id of the last invoice created and want to populate a hidden field on the line_items form with that number so that the line items know to which invoice they belong). Its easy in HTML but I am using the rails text_field method. I guessed at setting :value but it does not seem to do anything. Well, I''ve looked for a good hour now and can find no record of it. Please would someone help me. bruce PS. If it was in the api docs or the Agile web development book, please feel free to send abuse with your answer. I''ll take it in good cheer.
On 17/11/2005, at 3:10 PM, Bruce Balmer wrote:> > I need to programatically set the value of a field on a form (I > get the id of the last invoice created and want to populate a > hidden field on the line_items form with that number so that the > line items know to which invoice they belong). Its easy in HTML but > I am using the rails text_field method. I guessed at setting :value > but it does not seem to do anything.Typically you''d set it in the controller. You probably have something like @mything = Thing.new() in the "new" action in your controller. So to pre-fill the invoice id, you can try something like. @mything = Thing.new() @mything.invoice_id = 25 Then <%= text_field "mything", "invoice_id" %> will automatically be populated with the value "25". Without seeing an example of your existing controller and view, you''ll have to make the leap from this example to making it work in your code, but that should be enough to get you started. --- Justin French, Indent.com.au justin.french-zULN+VWqVOIpAS55Wn97og@public.gmane.org Web Application Development & Graphic Design
Hi Bruce, I''m not sure if you checked the docs on this but http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html#M000334 (I found the docs difficult to navigate at first but I''m starting to get the hang of them now.) - Peter On 11/16/05, Bruce Balmer <brucebalmer-ee4meeAH724@public.gmane.org> wrote:> > OK. This is embarrassing. > > I need to programatically set the value of a field on a form (I get > the id of the last invoice created and want to populate a hidden > field on the line_items form with that number so that the line items > know to which invoice they belong). Its easy in HTML but I am using > the rails text_field method. I guessed at setting :value but it does > not seem to do anything. > > Well, I''ve looked for a good hour now and can find no record of it. > Please would someone help me. > > bruce > > PS. If it was in the api docs or the Agile web development book, > please feel free to send abuse with your answer. I''ll take it in > good cheer. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails