Skip to content

Instantly share code, notes, and snippets.

@toddsiegel
Created January 10, 2013 08:10
Show Gist options
  • Save toddsiegel/4500351 to your computer and use it in GitHub Desktop.
Save toddsiegel/4500351 to your computer and use it in GitHub Desktop.
# invoices_controller.rb
helper_method :available_filters
def index
@invoices = Invoice.send(filter_scope)
end
private
def available_filters
["unpaid", "paid", "whatever"]
end
def filter_scope
filtered? ? params[:filter].to_sym : :all
end
def filtered?
available_filters.include? params[:filter]
end
# in the view
<ul>
<li><%= link_to "all", invoices_path %></li>
<% available_filters.each do |filter| %>
<li><%= link_to filter, invoices_path(:filter => filter) %></li>
<% end %>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment