Good day! Sometimes we want just to render a collection:
render partial: collection: @cars Sometimes we want to render a collection using custom partial name: render partial: 'car_short', collection: @cars Ok but if Car has has STI-subclasses we should write class Car < ActiveRecord::Base; def to_partial_path(); "cars/#{kind}"; end; end render collection: @cars But wait! Partial will be 'cars/bmw', 'cars/mercedes'. But sometimes I want to render a collection with '_short' postfix. But sometimes without it. But 'to_partial_path' is common... What to do? This brief article<http://blog.plataformatec.com.br/2012/01/my-five-favorite-hidden-features-in-rails-3-2/>, 4) Custom partial paths, says to do @cars.each do |car| render partial: "cars/#{car.kind}_short", locals: { car: car } end But this code is... I don't like to do so, do you? What about new 'render''s option? A 'postfix'/'prefix' options are nice for this example but... Another example. Partial name is related to your role for this object ('owner', 'admin', etc.): @cars.each do |car| render partial: "#{car.to_partial_path}_#{your_role_for(car)}", locals: { car: car } end What do you think? Is it a good idea? Thanx. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. For more options, visit https://groups.google.com/groups/opt_out.