Forum: Ruby on Rails Adding "id='xyz' " to a form_tag

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.
srj (Guest)
on 2009-02-05 05:49
(Received via mailing list)
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 %>
          <input class="actionButton" type="submit" value="Submit" />
        <% end %>

I tried this:

        <% form_tag :id => 'xyz', :controller =>
'my_controller', :action => 'my_action' do %>
          <input class="actionButton" type="submit" value="Submit" />
        <% 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.
Billy H. (Guest)
on 2009-02-05 05:53
(Received via mailing list)
<% 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:
>          <form id="xyz" action="/my_directory/my_action"
> method="post">
>
> 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
Shankar G. (Guest)
on 2009-02-05 06:00
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... .

enjoy ! have a great day.

cheers,
shankar.
Phlip (Guest)
on 2009-02-05 06:02
(Received via mailing list)
>     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...
srj (Guest)
on 2009-02-05 06:09
(Received via mailing list)
I did try with class= instead of id=, but I get the exact same result
Julian L. (Guest)
on 2009-02-05 06:12
(Received via mailing list)
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/
Shankar G. (Guest)
on 2009-02-05 06:14
Steve, Have you tried this
url(http://blog.invisible.ch/files/rails-reference-1.1... .
) ?

shankar.
Julian L. (Guest)
on 2009-02-05 06:14
(Received via mailing list)
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
Julian L. (Guest)
on 2009-02-05 06:15
(Received via mailing list)
That's not true. Ids are perfectly valid.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/
srj (Guest)
on 2009-02-05 06:20
(Received via mailing list)
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>
Shankar G. (Guest)
on 2009-02-05 06:21
Steve can you tell me when you are getting error and what error?
srj (Guest)
on 2009-02-05 06:27
(Received via mailing list)
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>
This topic is locked and can not be replied to.