how to do form parameter naming from the form tag?

Hi,

Just like with input tags in a form, where parameter naming can be influenced by modifying the tag name attribute…

<``input id``=``"person_name" name``=``"person[name]" type``=``"text" value``=``"Henry"``/>

…results in…

{'person' => {'name' => 'Henry'}}

(source: guides.rubyonrails.org/form_helpers.html#basic-structures)

Can I insert attributes into form_tag to customize the parameterization of all items inside? For example,

{‘whatever_i_want_to_use_as_a_key’ => {‘person’ => {‘name’ => ‘Henry’}}}

Thx,

Lille

You can use the “as” option on your form_for tag:

form_for(@person) will generate inputs like “person[name]”

form_for(@person, :as => “something[person]”) will generate an input like “something[session][email]”

Sorry, should have been “something[person][name]” instead of
“something[session][email]”

Yes it should work. Did you try it?

I would say though that you should use form_for rather than form_tag
if possible. So if the form is displaying data for an object then use
form_for.

If you are a beginner then, if you have not already done so, I suggest
you work right through some tutorials such as railstutorial.org (which
is free to use online), that will give you a good basic knowledge of
rails. Make sure you use a tutorial for rails 3 and install the
correct version of Rails.

Colin

I would say though that you should use form_for rather than form_tag

if possible. So if the form is displaying data for an object then use

form_for.

There was no especially good reason to try for this, except I happened to have a form that used form_tag and with no instance variable available for use with form_for.

Anyway, let me close this issue, noting that my conclusion is that there is no way to get parameter naming with form_tag like from form_for.

Lille

As I said, it should work with form_tag and form_for. What makes you
think that it does not?

By the way, there is no need to send a copy of the email directly to
me, just send it to the list.

Colin