content_tag FTW!

About those one-liners… How about turning this:

<% if logged_in? %>
  <p><%= link_to 'Edit', document_edit_path(@document) %></p>
<% end %>

into this:

<%= content_tag 'p', link_to('Edit', document_edit_path(@document)) if logged_in? %>

I don’t know about you, but to say that I’m impressed would be not enough. Available from Rails 2.0 upwards.

Published by

Paweł Gościcki

Ruby/Rails programmer.