I''m using Rails 1.2.3 and have been wrestling with the form_tag helper trying to get the HTML id for the form set. My form_tag initially looked like this: <% form_tag :controller => ''my_controller'', :action => ''my_action'' do %> and I thought it should be as easy as adding :html => {:id => ''my_id''}: <% form_tag :controller => ''my_controller'', :action => ''my_action'', :html => {:id => ''my_id''} do %> After all, that''s how the form_remote_tag works: <% form_remote_tag :controller => ''my_controller'', :action => ''my_action'', :html => {:id => ''my_id''} do %> Much to my chagrin, it didn''t work. I did a lot of searching and experimenting, and finally figured out that you have to make two changes to get it to work. First, you have to use a string literal for the url. Second, you can''t specify the :html hash key: <% form_tag ''/my_controller/my_action'', {:id => ''my_id''} do %> Two questions: 1) Does anyone know why the form_tag helper is inconsistent with both the form_remote_tag helper and the more Rails-traditional way of specifying urls (:controller, :action)? 2) Does anyone know if this behavior has been changed in 2.0? Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
<% form_tag {:controller => ''my_controller'', :action => ''my_action''}, :id => ''my_id'' do %> -Bill Phillip Koebbe wrote:> I''m using Rails 1.2.3 and have been wrestling with the form_tag > helper trying to get the HTML id for the form set. > > My form_tag initially looked like this: > > <% form_tag :controller => ''my_controller'', :action => ''my_action'' do %> > > and I thought it should be as easy as adding :html => {:id => ''my_id''}: > > <% form_tag :controller => ''my_controller'', :action => > ''my_action'', :html => {:id => ''my_id''} do %> > > After all, that''s how the form_remote_tag works: > > <% form_remote_tag :controller => ''my_controller'', :action => > ''my_action'', :html => {:id => ''my_id''} do %> > > Much to my chagrin, it didn''t work. I did a lot of searching and > experimenting, and finally figured out that you have to make two > changes to get it to work. First, you have to use a string literal > for the url. Second, you can''t specify the :html hash key: > > <% form_tag ''/my_controller/my_action'', {:id => ''my_id''} do %> > > Two questions: > > 1) Does anyone know why the form_tag helper is inconsistent with both > the form_remote_tag helper and the more Rails-traditional way of > specifying urls (:controller, :action)? > 2) Does anyone know if this behavior has been changed in 2.0? > > Peace, > Phillip > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry, forgot to answer #2. There has been talk on the rails-core list about making this, along with link_to and others follow the single hash convention, but it has not been changed yet. -Bill Phillip Koebbe wrote:> I''m using Rails 1.2.3 and have been wrestling with the form_tag > helper trying to get the HTML id for the form set. > > My form_tag initially looked like this: > > <% form_tag :controller => ''my_controller'', :action => ''my_action'' do %> > > and I thought it should be as easy as adding :html => {:id => ''my_id''}: > > <% form_tag :controller => ''my_controller'', :action => > ''my_action'', :html => {:id => ''my_id''} do %> > > After all, that''s how the form_remote_tag works: > > <% form_remote_tag :controller => ''my_controller'', :action => > ''my_action'', :html => {:id => ''my_id''} do %> > > Much to my chagrin, it didn''t work. I did a lot of searching and > experimenting, and finally figured out that you have to make two > changes to get it to work. First, you have to use a string literal > for the url. Second, you can''t specify the :html hash key: > > <% form_tag ''/my_controller/my_action'', {:id => ''my_id''} do %> > > Two questions: > > 1) Does anyone know why the form_tag helper is inconsistent with both > the form_remote_tag helper and the more Rails-traditional way of > specifying urls (:controller, :action)? > 2) Does anyone know if this behavior has been changed in 2.0? > > Peace, > Phillip > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 12, 2007, at 1:26 PM, William Pratt wrote:> > <% form_tag {:controller => ''my_controller'', :action => > ''my_action''}, :id => ''my_id'' do %> > > -Bill >Hi Bill, That results in a compile error. The only way that I can get it to work is to use a string literal (or variable, I suppose...haven''t tried that) for the url. Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 12, 2007, at 4:02 PM, Phillip Koebbe wrote:> On Dec 12, 2007, at 1:26 PM, William Pratt wrote: >> <% form_tag {:controller => ''my_controller'', :action => >> ''my_action''}, :id => ''my_id'' do %> >> >> -Bill > > Hi Bill, > > That results in a compile error. The only way that I can get it to > work is to use a string literal (or variable, I suppose...haven''t > tried that) for the url. > > Peace, > PhillipTry it like: <% form_tag({:controller => ''my_controller'', :action => ''my_action''}, :id => ''my_id'') do %> The first { is probably being seen as starting a block. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 12, 2007, at 3:21 PM, Rob Biedenharn wrote:> > Try it like: > > <% form_tag({:controller => ''my_controller'', > :action => ''my_action''}, > :id => ''my_id'') do %> > > The first { is probably being seen as starting a block. > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.orgRob, Putting the parentheses around the parameters made it output correctly. If only it would have been as easy as form_remote_tag to begin with... Bill, Thanks for your comments as well. Maybe someone will be a bug in their pants and decide to fix it. Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---