Hi Guys, I got a helper method that I want to use more than once. The only thing that will change will be the variable that is used to collect the data. For example; def render_blocks position = 0 @variable.collect { |question, answer| position += 1 "<h3>#{position}. <a name=\"#{block_to_anchor(question)}\"></a>#{question}</h3>" + content_tag(''div'', simple_format(answer)) } end I need to call this helper method from different pages. Can I pass something through to the helper method that changes the variable name to the one I want.. For example <%= render_blocks :page => ''free'' %> on one page that changed @variable to @free and <%= render_blocks :page => ''faq'' %> that changes @variable to @faq. Any help would be greatly appreciated. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 Fri, Mar 6, 2009 at 3:14 PM, Roger Muthton <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi Guys, > > I got a helper method that I want to use more than once. The only thing > that will change will be the variable that is used to collect the data. > For example; > > def render_blocks > position = 0 > -hC4i9Aumtbv1b8PXN/seAQ@public.gmane.org { |question, answer| > position += 1 > "<h3>#{position}. <a > name=\"#{block_to_anchor(question)}\"></a>#{question}</h3>" + > content_tag(''div'', simple_format(answer)) > } > end > > > I need to call this helper method from different pages. Can I pass > something through to the helper method that changes the variable name to > the one I want..Just declare a parameter in your helper method à la: def render_blocks(my_variable) my_variable.collect end You then call it in your view and pass the variable that is valid for that view. <%= render_blocks(@free) %> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Just declare a parameter in your helper method à la: > > def render_blocks(my_variable) > my_variable.collect > end > > You then call it in your view and pass the variable that is valid for > that view. > > <%= render_blocks(@free) %>grand. cheers -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---