Joshua Muheim
2006-Aug-16 16:32 UTC
[Rails] Overwrite form helper methods and call old ones in new ones?
Hi all All my forms should look the same, so I think always putting the right div etc. tags around them is a violation of the DRY principle. Until now my forms look like that: <div class="text_field"> <label for="news_item_subject">Subject:</label> <%= text_field "news_item", "subject" %> </div> Now I want the default form helper methods to do that all for me: <%= text_field "news_item", "subject", :label => "Subject" %> ...should produce exactly the same output as the HTML above. Now I don''t really know how to call the old text_field method to produce the input tag from within my new method: application_helper.rb: def text_field(object_name, method, options = {}) ret_val = "<div class=\"text_field\">\n" ret_val += text_field object_name, method, options # Don''t become recursive, just call the now overwritten method! ret_val += "</div>\n" end Thanks for help. :-) Joshua -- Posted via http://www.ruby-forum.com/.
Kyle Slattery
2006-Aug-16 17:56 UTC
[Rails] Overwrite form helper methods and call old ones in new ones?
If you have the Rails Recipe book, I know there''s a recipe in there relating to this... On 8/16/06, Joshua Muheim <forum@josh.ch> wrote:> > Hi all > > All my forms should look the same, so I think always putting the right > div etc. tags around them is a violation of the DRY principle. > > Until now my forms look like that: > > <div class="text_field"> > <label for="news_item_subject">Subject:</label> <%= text_field > "news_item", "subject" %> > </div> > > Now I want the default form helper methods to do that all for me: > > <%= text_field "news_item", "subject", :label => "Subject" %> > > ...should produce exactly the same output as the HTML above. > > Now I don''t really know how to call the old text_field method to produce > the input tag from within my new method: > > application_helper.rb: > def text_field(object_name, method, options = {}) > ret_val = "<div class=\"text_field\">\n" > ret_val += text_field object_name, method, options # Don''t become > recursive, just call the now overwritten method! > ret_val += "</div>\n" > end > > Thanks for help. :-) > Joshua > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060816/82778c79/attachment.html
Joshua Muheim
2006-Aug-16 18:11 UTC
[Rails] Re: Overwrite form helper methods and call old ones in new o
Kyle Slattery wrote:> If you have the Rails Recipe book, I know there''s a recipe in there > relating > to this...Damn, I wanted to order it since quite some weeks, but I don''t have a Credit Card yet, but I will in some days... Anyone knows further informations? -- Posted via http://www.ruby-forum.com/.
Max Muermann
2006-Aug-16 22:47 UTC
[Rails] Overwrite form helper methods and call old ones in new ones?
you want to investigate the alias method. Googling for "ruby alias" will turn up enough to get you started. Max
Joshua Muheim
2006-Aug-17 06:42 UTC
[Rails] Re: Overwrite form helper methods and call old ones in new o
Max Muermann wrote:> you want to investigate the alias method. > > Googling for "ruby alias" will turn up enough to get you started. > > MaxThank you. I''m gonna try it. :-) -- Posted via http://www.ruby-forum.com/.
Seemingly Similar Threads
- Turn element hidden by default (ajax question)
- ActionView::Helpers::FormHelper instance methods should take an object reference rather than an object_name.
- add method parameter for form helper
- setting a value of text_field from a controller
- best methods for strings and structures?