Hello, Are there any guidelines as to when helpers or partials are a better option. If there is a lot of markup we are using partials, otherwise it has been up to the developer. Is there an established best practice? Thanks, Dan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hello, Are there any guidelines as to when helpers or partials are a better option. If there is a lot of markup we are using partials, otherwise it has been up to the developer. Is there an established best practice? Thanks, Dan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Usually I favor helpers over partials when there''s more logic coding than markup and "display" coding involved. For example: def display_date_range(start_date, end_date = false) end_date = nil if end_date == start_date [start_date, end_date].compact.each{|date| date = date.to_s(:view) if date.respond_to? :year}.join('' - '') end That really feels more like it should be a helper than a partial. I guess that''s what matters - doing whatever feels right :) Daniel On Friday 17 November 2006 8:55 am, Dan Munk wrote:> Hello, > > Are there any guidelines as to when helpers or partials are a better > option. If there is a lot of markup we are using partials, otherwise > it has been up to the developer. > > Is there an established best practice? > > Thanks, > Dan > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
+1 Helpers == logic Partials are for rendering parts of views. Leverage them both by making a helper call a partial :) On 11/17/06, Daniel Higginbotham <daniel-4cOk6EWy6wjNj93mkU9IYrqjc7CnNF17@public.gmane.org> wrote:> > > Usually I favor helpers over partials when there''s more logic coding than > markup and "display" coding involved. For example: > > def display_date_range(start_date, end_date = false) > end_date = nil if end_date == start_date > [start_date, end_date].compact.each{|date| date = date.to_s(:view) if > date.respond_to? :year}.join('' - '') > end > > That really feels more like it should be a helper than a partial. I guess > that''s what matters - doing whatever feels right :) > > Daniel > > > On Friday 17 November 2006 8:55 am, Dan Munk wrote: > > Hello, > > > > Are there any guidelines as to when helpers or partials are a better > > option. If there is a lot of markup we are using partials, otherwise > > it has been up to the developer. > > > > Is there an established best practice? > > > > Thanks, > > Dan > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dan Munk wrote:> Hello, > > Are there any guidelines as to when helpers or partials are a better > option. If there is a lot of markup we are using partials, otherwise > it has been up to the developer. > > Is there an established best practice? > > Thanks, > DanDan, I''ve noticed something about forums like this. Anybody can write almost anything in their original post, and it may go unnoticed, but as soon as somebody messes up in a reply, people are all over it. For that reason, even though I''m a newby, I often reply to things that interest me just to bring the "group elders" out of hiding and get the real answer. To that end, I offer the following... I tend to think of helpers as mostly eRB code, and partials as mostly html. Need to format a date or have a loop that fixes up some tabs or something, helper time. Have a form that gets shown/hidden via ajax, that''s a partial. Partials are great for ajax views where you have lots of stuff happening in the same view, but not all at once. There can be so much stuff there that it gets really cluttered. Partials are a great way to make the view into a sort of skeleton or outline of the page, and put all the gory details off in the partials. jp -- 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 -~----------~----~----~----~------~----~------~--~---
Here''s something to think about: Remember that you can apply a partial to a collection? Assuming this partial: _product.rhtml <%=h(product.name) %> <%=h(product.description) %> <%=number_to_currency(product.price) %> This would render that partial once for each entry in the @products collection: <%=render :partial=>"product", :collection=>@products %> What does the iteration? the helper "render". This is a prime example of how you can use helpers in Rails. Things like number_to_currency, h, link_to, link_to_unless_current, image_tag, text_field, etc... are all helpers. They''re methods that produce output. Helpers don''t always exist in the view... they''re just methods in a module. How you use them is up to you, but the idea is supposed to be that helpers keep your logic out of the view, and partials provide an easy mechanism for reuse. On 11/17/06, Jeff Pritchard <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Dan Munk wrote: > > Hello, > > > > Are there any guidelines as to when helpers or partials are a better > > option. If there is a lot of markup we are using partials, otherwise > > it has been up to the developer. > > > > Is there an established best practice? > > > > Thanks, > > Dan > > Dan, > I''ve noticed something about forums like this. Anybody can write almost > anything in their original post, and it may go unnoticed, but as soon as > somebody messes up in a reply, people are all over it. > > For that reason, even though I''m a newby, I often reply to things that > interest me just to bring the "group elders" out of hiding and get the > real answer. To that end, I offer the following... > > I tend to think of helpers as mostly eRB code, and partials as mostly > html. Need to format a date or have a loop that fixes up some tabs or > something, helper time. Have a form that gets shown/hidden via ajax, > that''s a partial. > > Partials are great for ajax views where you have lots of stuff happening > in the same view, but not all at once. There can be so much stuff there > that it gets really cluttered. Partials are a great way to make the > view into a sort of skeleton or outline of the page, and put all the > gory details off in the partials. > > jp > > -- > 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 -~----------~----~----~----~------~----~------~--~---