Two snippets on how to refactor a ruby application using block helpers.

Poor coding approach :
1, Insert HTML code as strings

<%= link_to "<strong>#{}</strong><span>
            #{pluralize(product.topic_count(company), 'topic')}</span>",
    href, :class => "product_label" %>

2. Use condinional sentences to display content :

 <% if @user.rol == :admin %>
   Section only for admins
 <%end >


1. Replace the old lin_to with a block helper (via educate, liberate):

<% link_to browse_url(product), :class => "product_label" do %>  <%= %>

(<%= pluralize(product.topic_count(company), 'topic') %>)

<% end %>

2. Use a code block helper to insolate the rol administation logic :

 <% @user.admin? do %>
   section only for admins

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: