So I am making a rails app that lets users search logs by date. So in my controller I have set it to look for logs from the DB using the parameters. However when it first loads, there are no parameters passed to the controller, so it gives a nil error.
Is there a way to set the default parameters so that it won't have this error?
Here are the controller and view snippets:
user_sessions_controller.rb
[...] def admin
@start_date = Date::civil(params[:find_dates] ['start_date(1i)'].to_i, params[:find_dates]['start_date(2i)'].to_i, params[:find_dates]['start_date(3i)'].to_i)
@end_date = Date::civil(params[:find_dates]["end_date(1i)"].to_i, params[:find_dates]["end_date(2i)"].to_i, params[:find_dates] ["end_date(3i)"].to_i)
@logs = Log.all(:conditions => ["updated_at between ? and ?", @start_date, @end_date], :order => "updated_at DESC")
respond_to do |format| format.html { render :action => 'admin' } format.csv { render :csv => @logs } end
end [...]
admin.html.erb
[...] <div id="find_dates"> <% form_tag '/find_dates' do %> <p> <%= label_tag "start_date", "Start Date" %> <%= date_select "find_dates", "start_date", :order => [:month, :day, :year] %> </p> <p> <%= label_tag "end_date", "End Date" %> <%= date_select "find_dates", "end_date", :order => [:month, :day, :year] %> </p> <%= submit_tag "Find" %> <% end %> </div> [...]