Created
January 10, 2013 08:10
-
-
Save toddsiegel/4500351 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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