Adding "id='xyz' " to a form_tag


#1

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.


#2

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

On Thu, Feb 5, 2009 at 11:49 AM, srj removed_email_address@domain.invalid wrote:

I tried this:

Thanks,

Steve J.


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

CFC on Rails:
http://zusocfc.blogspot.com

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


#3

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.


#4

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


#5
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…


#6

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/


#7

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

shankar.


#8

That’s not true. Ids are perfectly valid.

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


#9

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.
<removed_email_address@domain.invalid


#10

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


#11

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. removed_email_address@domain.invalid


#12

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. removed_email_address@domain.invalid