Attempting to create a filter select to find schedules with coursedates within a given date range:
AdminController:
def find_schedules
if params[:start_date] && params[:end_date]
start_date = params[:start_date]
end_date = params[:end_date]
@schedules = Schedule.find(:all, :conditions => {:coursedate => start_date..end_date})
redirect_to :action => 'find_results'
end
end
find_schedules view:
<% form_tag(find_schedules_path) do %>
<%= select_date Date.today, :prefix => :start_date %>
<%= select_date Date.today, :prefix => :end_date %>>
<%= submit_tag "Submit", :disable_with => "Submitting..." %>
<% end %>
Error:
Processing AdminController#find_schedules (for ...) [POST]
Parameters: {"start_date"=>{"month"=>"3", "day"=>"23", "year"=>"2011"}, "commit"=>"Submit", "authenticity_token"=>"...", "end_date"=>{"month"=>"2", "day"=>"16", "year"=>"2012"}}
ArgumentError (bad value for range)
I always seem to have trouble with date/datetime stuff. coursedate is a datetime field in the schedules table, if that makes any difference. I only need to search for dates, not times. Do I need to transform the data type somehow because of how mysql stores it? Or... what else am I doing wrong? Thanks in advance for your help.
Getting much closer after bdon's help, thank you! Now I'm getting an undefined method error, but I should be able to figure that out:
ActionView::TemplateError (undefined method `each' for nil:NilClass) on line #26 of /admin/find_results.html.erb:
25: <tr class="<%= cycle('odd', 'even') %>">
26: <% @schedules.each do |schedule| %>