Forum: Ruby on Rails How can I append a text_field_tag to a form_for?

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.
Heinz S. (Guest)
on 2009-03-12 17:35
Hello people,

how can I append a text_field_tag to a form_for? When I submit the form
all text_field_tags are not being appended to the params...
Tom H. (Guest)
on 2009-03-12 18:02
You probably just have a typo in your code...


If you include a

   <%= text_field_tag 'firstname' %>

in your form, then you can get the value in the controller using

   params[:firstname]


If you use nested resources, a

   <%= text_field_tag 'user[firstname]' %>

in your form, will result in

   params[:user][:firstname]

in your controller.

Regards,
Tom
Heinz S. (Guest)
on 2009-03-12 18:07
I have it exactly like you said:
<%= text_field_tag "type[#{cat.name}]", 0, :size => 1, :id =>
"type_#{cat.id}", :disabled => true %>
or rather:
<input id="type_826889617" type="text" value="0" size="1"
name="type[Tarnung]" disabled="disabled"/>

But I only get the fields used with the form_for (all form.text_field
inputs). None of the text_field_tags is in the params array.
Ar C. (Guest)
on 2009-03-12 18:31
Disabled items don't come back in the params, perhaps you need a hidden
field?

I just tweaked the first name field on a person edit form to be
disabled, and the value did not come back in the params.
Heinz S. (Guest)
on 2009-03-12 19:14
Yeah, that was it. Thanks :)
This topic is locked and can not be replied to.