Using block helpers to make your views pretty
I was watching the code review that Jamis Buck and Marcel Molina did for the Mountain West Ruby Conference and one really nice idea that grabbed my attention was using block helpers to separate sections in views.
Let's say you have a view and you need to render a partial with some content which only people who love delicious pickles should see.
<% if @user.loves_delicious_pickles? %> <%= render :partial => "pickles" %> <% end %>That's perfectly fine, but should your pickle logic get more complicated, you'll be stuck with an ugly looking conditional statement in your view.
The alternative would be to add a helper to your controller and move all your logic in there
def lover_of_delicious_pickles yield if @user.loves_delicious_pickles? endWhich would turn your view into something to the tune of
<% lover_of_delicious_pickles do %> <%= render :partial => "pickles" %> <% end %>Granted, this isn't the best example but the idea itself is really good, and should at least make your code easier to understand. More on this here.
