Created
June 8, 2010 00:18
-
-
Save rduarte/429407 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# /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 |
This file contains hidden or 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
http://localhost:3000/timesheets?by_employee=1&by_place=3 |
This file contains hidden or 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
# /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 |
This file contains hidden or 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
# /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