Lee.Longmore-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2008-Dec-18 09:07 UTC
form_tag - howto call with self.send?
I have the following code in a form helper Module: def form_tag_helper(options = {}) url = url_for(:action => "#{@controller.action_name}") "#{self.send(:form_tag, url, options)}" end which I call from several views e.g. <%= form_tag_helper %> <table> <%#= form_input :text_field, "login", :size => 30 %><br/> <%#= form_input :password_field, "password", :size => 30 %><br/></table> <div class="button-bar"> <%#= button_helper ''login'' %> <%#= link_helper ''login_signup'', :action => ''signup'' %> <%#= link_helper ''login_forgot_password'', :action => ''forgot_password'' %> </div> The code -- which I have modified from the SaltedHashLoginGenerator (replace deprecated start_form_tag with form_tag) -- seems to generate an html form correctly. I am however conscious that form_tag (when used in the manner above) should have a do...end block surrounding the form elements and the above code does not respect this. I would appreciate any views on this and suggestions on how I might add a do...end block. Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
In Ruby, you can pass a block (a chunk of code) to a method call, and then run that code by calling yield in the method. This might be what you need... A caveat: I''m pretty much a noob, so anything I say might be wrong :) This page looks like it might be helpful: http://tutorial.jcwcn.com/Web-Design/Ruby-on-Rails/Helpers/2007-08-25/3066.html Good luck! On Dec 18, 1:07 am, "Lee.Longm...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org" <Lee.Longm...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> I have the following code in a form helper Module: > > def form_tag_helper(options = {}) > url = url_for(:action => "#...@controller.action_name}") > "#{self.send(:form_tag, url, options)}" > end > > which I call from several views e.g. > > <%= form_tag_helper %> > <table> > <%#= form_input :text_field, "login", :size => 30 %><br/> > <%#= form_input :password_field, "password", :size => 30 %><br/ > > </table> > > <div class="button-bar"> > <%#= button_helper ''login'' %> > <%#= link_helper ''login_signup'', :action => ''signup'' %> > <%#= link_helper ''login_forgot_password'', :action => > ''forgot_password'' %> > </div> > > The code -- which I have modified from the SaltedHashLoginGenerator > (replace deprecated start_form_tag with form_tag) -- seems to generate > an html form correctly. I am however conscious that form_tag (when > used in the manner above) should have a do...end block surrounding the > form elements and the above code does not respect this. > > I would appreciate any views on this and suggestions on how I might > add a do...end block. > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 18 Dec 2008, at 09:07, Lee.Longmore-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org wrote:> > I have the following code in a form helper Module: > > def form_tag_helper(options = {}) > url = url_for(:action => "#{@controller.action_name}") > "#{self.send(:form_tag, url, options)}" > end >I''d guess something along the line of def form_tag_helper(options = {}, &block) url = url_for(:action => "#{@controller.action_name}") form_tag( url, options, &block) end and then use form_tag_helper as you would form_tag, ie <% form_tag_helper do %> ... <% end > should do the trick Fred> which I call from several views e.g. > > <%= form_tag_helper %> > <table> > <%#= form_input :text_field, "login", :size => 30 %><br/> > <%#= form_input :password_field, "password", :size => 30 %><br/ >> > </table> > > <div class="button-bar"> > <%#= button_helper ''login'' %> > <%#= link_helper ''login_signup'', :action => ''signup'' %> > <%#= link_helper ''login_forgot_password'', :action => > ''forgot_password'' %> > </div> > > The code -- which I have modified from the SaltedHashLoginGenerator > (replace deprecated start_form_tag with form_tag) -- seems to generate > an html form correctly. I am however conscious that form_tag (when > used in the manner above) should have a do...end block surrounding the > form elements and the above code does not respect this. > > I would appreciate any views on this and suggestions on how I might > add a do...end block. > > Thanks! > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Lee.Longmore-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2008-Dec-19 10:19 UTC
Re: form_tag - howto call with self.send?
Thanks! That did do the trick :) On 18 Dec, 18:39, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 18 Dec 2008, at 09:07, Lee.Longm...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org wrote: > > > > > I have the following code in a form helper Module: > > > def form_tag_helper(options = {}) > > url = url_for(:action => "#...@controller.action_name}") > > "#{self.send(:form_tag, url, options)}" > > end > > I''d guess something along the line of > def form_tag_helper(options = {}, &block) > url = url_for(:action => "#...@controller.action_name}") > form_tag( url, options, &block) > end > > and then use form_tag_helper as you would form_tag, ie > > <% form_tag_helper do %> > ... > <% end > > > should do the trick > > Fred > > > which I call from several views e.g. > > > <%= form_tag_helper %> > > <table> > > <%#= form_input :text_field, "login", :size => 30 %><br/> > > <%#= form_input :password_field, "password", :size => 30 %><br/ > > > </table> > > > <div class="button-bar"> > > <%#= button_helper ''login'' %> > > <%#= link_helper ''login_signup'', :action => ''signup'' %> > > <%#= link_helper ''login_forgot_password'', :action => > > ''forgot_password'' %> > > </div> > > > The code -- which I have modified from the SaltedHashLoginGenerator > > (replace deprecated start_form_tag with form_tag) -- seems to generate > > an html form correctly. I am however conscious that form_tag (when > > used in the manner above) should have a do...end block surrounding the > > form elements and the above code does not respect this. > > > I would appreciate any views on this and suggestions on how I might > > add a do...end block. > > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---