I am working with a collection of objects that have a growing number of states. Each state requires a different layout/html wrapper. To reduce the need for conditional statements within the partial or template, I thought it might be nice if the layout option could be set dynamically using a proc or better yet a method.
An overly simplistic example would be something like this... <%# app/views/users/_private_layout.html.erb %> <h2>User is private</h2> <section> <%= yield %> </section> <%# app/views/users/_public_layout.html.erb %> <h2><%= user.name %></h2> <a href="users/profile"> <%= yield %> </a> <%# app/views/users/index.html.erb %> <%= render partial: "user", collection: users, layout: -> user { user. private? ? "private_layout" : "public_layout" } %> I imagine there are already nice patterns to handle this sort of case but I thought I'd throw the idea out there! Thanks! -- 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 https://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.