ms
2008-Oct-16 14:22 UTC
Modularisation: Using helper generating HTML output vs. using partials
Hey, I''ve got a general question: when do I use helper and when I do use partials to modularise certain gui elements? For example: I''ve got a faq list. Each item can be folded and unfolded using ajax. FAQ foo -> question 1 -> question 2 -> question 3 So, I wrote a helper "faq_li_tag(args)" which takes the question and answer for parameters and generates the HTML output. But I also could have made a partial which creates the corresponding output. What''s the best solution? What are the criterias for this decision in general? Thank you very much! Best regards, ms --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jeff
2008-Oct-16 15:17 UTC
Re: Modularisation: Using helper generating HTML output vs. using partials
On Oct 16, 9:22 am, ms <m...-cGBD8117FJM@public.gmane.org> wrote:> Hey, > > I''ve got a general question: when do I use helper and when I do use > partials to modularise certain gui elements? > > For example: I''ve got a faq list. Each item can be folded and unfolded > using ajax. > > FAQ foo > -> question 1 > -> question 2 > -> question 3 > > So, I wrote a helper "faq_li_tag(args)" which takes the question and > answer for parameters and generates the HTML output. > > But I also could have made a partial which creates the corresponding > output. > > What''s the best solution? What are the criterias for this decision in > general? > > Thank you very much! > > Best regards, > msI use partials to factor out view templates to make them more readable, and so that I can reuse portions of a view in other templates. I use helpers whenever view logic is starting to get intertwined with the view code. So presentation-only code is in the views/partials, and any logic (is this user an admin? should they see a sidebar now? etc.) goes into helpers. Jeff purpleworkshops.com softiesonrails.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 -~----------~----~----~----~------~----~------~--~---