Skip to content

Instantly share code, notes, and snippets.

@rduarte
Created June 8, 2010 00:18
Show Gist options
  • Save rduarte/429407 to your computer and use it in GitHub Desktop.
Save rduarte/429407 to your computer and use it in GitHub Desktop.
# /app/controllers/timesheets_controller.rb
class TimesheetsController < ApplicationController
has_scope :by_employee
has_scope :by_place
def index
@timesheets = apply_scopes(Timesheet).all
end
end
http://localhost:3000/timesheets?by_employee=1&by_place=3
# /app/models/timesheet.rb
class Timesheet < ActiveRecord::Base
named_scope :by_employee, proc { |employee| { :conditions => { :employee_id => employee } } }
named_scope :by_place, proc { |place| { :conditions => { :place_id => place } } }
end
# /app/views/timesheets/_filter.html.erb
<% form_tag ('/timesheets', :method => :get) do -%>
<%= select_tag 'by_employee', options_for_select(@employees, params[:by_employee].to_i) %>
<%= select_tag 'by_place', options_for_select(@places, params[:by_place].to_i) %>
<%= content_tag(:button, "Search", :type => "submit") %>
<% end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment