FormTagHelper form names: possible?


#1

Thank you to everybody that has helped me since I signed up. I’m flying
along thanks to you.

I have a question about the FormTagHelper “start_form_tag”: I’ve been
trying to figure out how to get Rails to output a “name” attribute for
my form so I can hook in a Javascript to focus on a field inside of it
on load, but it doesn’t look like I can do it. I’m not sure how to read
the API; it doesn’t have any examples. Everything I put into the command
just appends information to the action after a question mark or gives me
an error. I’ve tried putting name=“myformname” into double quotes,
single quotes, curly braces, brackets, you name it, but nothing works.
I’m beginning to think I should just code it in with HTML and forget
using the FormTagHelpers for form declarations entirely if I need any
attributes except “action” and “method”.

Anybody know if I’m right or wrong here?


#2

I have a question about the FormTagHelper “start_form_tag”: I’ve been
trying to figure out how to get Rails to output a “name” attribute for
my form so I can hook in a Javascript to focus on a field inside of it
on load, but it doesn’t look like I can do it. I’m not sure how to read
the API; it doesn’t have any examples. Everything I put into the command
just appends information to the action after a question mark or gives me
an error.
<…>
Anybody know if I’m right or wrong here?

start_form_tag accepts two hashes - one for url_for and second one for
html options, so
you must explicitly separate them with {}.

This should work:

<%= form_tag( {:action => :my_action}, {:name => :my_form} ) %>

Regards,
Rimantas

http://rimantas.com/