Bad Smells sign in rails code.

  1. Calling find on a model direct
    1
    2
    3
    4
    %  Sales.find_all_by_region(params[:region]) 
                                    .each do |t| %>
    
      # some inteligent code
    
    <% end %>
  2. alling find on an association
  3. Conditionally inserting content if/else clauses, case statements, etc
    1
    <% if current_user.admin? %>Admins see this<% end %>
  4. Doing a complex inline map, sort, select, etc on a collection
  5. 1
    
    2
    <% applications.sort_by{|app| [app.priority, app.creator.name]}
                                  .each do |app|
    <% end %>
  6. assigning temporary variables
    1
    
    2
    
    3
    
    4
    
    5
    
    
    <% indicator_id = "loading_indicator_#{item.id}" %>
    
        <%= link_to_remote("Show Status",:url => item_path(item),
    
            :loading => "$('#{indicator_id}').show()",
    
            :complete => "$('#{indicator_id}').hide()",) %>
    
    <%= image_tag('progress.gif', :id => indicator_id)%>
    
    

When V is for Vexing: Patterns to DRY Up Your Views

Advertisements

No comments yet

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: