Adding "id='xyz' " to a form_tag

I am using the form_tag_helper to create a form, but I want to give it
an ID so I can style the elements within the form. I currently have
the following:

    <% form_tag :controller => 'my_controller', :action =>

‘my_action’ do %>

<% end %>

I tried this:

    <% form_tag :id => 'xyz', :controller =>

‘my_controller’, :action => ‘my_action’ do %>

<% end %>

This compiles and runs ok with no errors, but it treats the ID= as a
parameter for my URL - not what I want. Is there a way to use
form_tag to generate HTML similar to this:

      <form id="xyz" action="/my_directory/my_action"

method=“post”>

Thanks,

Steve J.

<% form_tag {:controller => “…”}, {:id => “xyz”} %>
Try it?

On Thu, Feb 5, 2009 at 11:49 AM, srj [email protected] wrote:

I tried this:

Thanks,

Steve J.


TWRUG Blog:
http://blog.rubyonrails.org.tw

CFC on Rails:

Only two surfaces of a box:
http://blog.pixnet.net/zusocfc

Hi Steve!

 Try this   <%= form_tag :action => 'my_action', :id =>'xyz' %> and 

I think this manual will be helpful to
you.http://blog.invisible.ch/files/rails-reference-1.1.html#htmlforms .

enjoy ! have a great day.

cheers,
shankar.

I did try with class= instead of id=, but I get the exact same result

I am using the form_tag_helper to create a form, but I want to give it
an ID so I can style the elements within the form.  I currently have
the following:

Style things with classes unless you must use IDs. I can’t think of a
reason.

Rails is so flexible that, before you know it, you will be cloning this
form and
en-partialling it into your page more than once, and IDs must be unique
to their
document…

Look at the Api. You need to supply two hashed rather than one. The
second has
HTML options. The first is the URL

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

Steve, Have you tried this
url(http://blog.invisible.ch/files/rails-reference-1.1.html#htmlforms .
) ?

shankar.

That’s not true. Ids are perfectly valid.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

That won’t work.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

On 05/02/2009, at 3:00 PM, Shankar G.
<[email protected]

Steve can you tell me when you are getting error and what error?

Thanks everyone for all the help . . .

When I tried it like this, I got a compile error:
<% form_tag ( {:controller => ‘my_controller’, :action =>
‘my_action’ }, {:id => ‘xyz’}) do %>

When I removed the second set of braces { }, like this, it works!!!

<% form_tag ( {:controller => ‘my_controller’, :action =>
‘my_action’ }, :id => ‘xyz’) do %>

Thanks again, I appreciate all the suggestions!

On Feb 4, 11:14 pm, Shankar G. [email protected]

I just added the extra braces back in so I could see the error again,
but now it does not complain - I must have had something extra or
something missing. So I guess it works both ways.

On Feb 4, 11:21 pm, Shankar G. [email protected]