I have a controller that has two actions: "show", "show_modify". These have very similar yet slightly different views, i.e show_modify has different div classes, has extra links/buttons and so on.
From what I've seen there are a few ways to approach this in rails:
Make one template for the two and just add conditions inside:
<% if param[:action]=="show_modify"> <% ... %> <% end %>
yet there are so many differences that this seems very ugly and repetitious, and also is this some kind of violation of the seperation of church and state (I'm not a MVC expert... )The partial way: For every element that is displayed differently create two partials, one for each action. The views would look something like this:
# show_modify
render :partial '_general_stuff'
render :partial => '_blabla_show_modify'# show
render :partial => '_general_stuff'
render :partial => '_blabla_show'
Yet this will violate DRY, because there are overlapping elements. I can continue making more sub partials, but it's basically turtles all the way down - eventually you have to go if/else if you dont want to repeat yourself.partials with locals:
if show
render :partial = '_blabla', :locals => {:bckgrnd => 'blue', :button => 'yes' ....}
but this is another lots-o-ifs solution....
Any better options out there? content_for maybe? I'm kind of a rails noob+, so i might have missed something altogether....
Thanks :)