Tag Archives: rails

Prefer `if object.present?` over `if object`

So you’ve got a controller method class DressesController < ApplicationController def show @dress = Dress.find_by(params.permit(:id)) end end And a view <div class=”<%= dress ? ‘dress&.status’ : ” %>”>Status Indicator</div> Looks good! Works great! Now your app grows, and you have a lot of other views that use the dress. Long after your view has been […]