Forum: Ruby on Rails Sorry that this question is so dumb but....

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
brucebalmer (Guest)
on 2005-11-17 06:12
(Received via mailing list)
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.
justin.french (Guest)
on 2005-11-17 07:03
(Received via mailing list)
On 17/11/2005, at 3:10 PM, Bruce B. 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 F., Indent.com.au
removed_email_address@domain.invalid
Web Application Development & Graphic Design
petermichaux (Guest)
on 2005-11-17 08:25
(Received via mailing list)
Hi Bruce,

I'm not sure if you checked the docs on this but

http://api.rubyonrails.com/classes/ActionView/Help...

(I found the docs difficult to navigate at first but I'm starting to get
the
hang of them now.)

- Peter
This topic is locked and can not be replied to.