I currently have a controller which produces a report. This is the controller:
def last5days
#@monday = (Time.now).at_beginning_of_week
@monday = (Time.now).months_ago(1)
#@friday = 5.days.since(@monday)-1.second
@friday = (Time.now)
@sent_emails = ContactEmail.all(:conditions => ['date_sent >= ? and date_sent <= ?', @monday, @friday])
@made_calls = ContactCall.all(:conditions => ['date_sent >= ? and date_sent <= ?', @monday, @friday])
@letters_sent = ContactLetter.all(:conditions => ['date_sent >= ? and date_sent <= ?', @monday, @friday])
@contacts_added = Contact.all(:conditions => ['date_entered >= ? and date_entered <= ?', @monday, @friday])
#@table = ContactEmail.report_table(:all,
# :conditions => ['date_sent >= ? and date_sent <= ?', @monday, @friday])
#@grouping = Grouping(@table, :by => "email_id")
end
Instead of hardcoding monday
and friday
, I want to have an interface where someone can select the start and end dates, hit submit, and the output gets returned.
I'm having troubling finding an example or knowing exactly what to do.
I started with a new view:
<%= render :partial => 'form' %>
<div id = 'display'>
</div>
I want the output from the controller to be displayed in "display" via Ajax.
I tried to create the form as follows:
<% remote_form_for do |f| %>
<p>
<%= f.label :start_date %><br />
<%= f.date_select_tag :start_date %>
</p>
<p>
<%= f.label :end_date %><br />
<%= f.date_select_tag :end_date %>
</p>
<p><%= f.submit "Submit" %></p>
<% end %>
And then my plan was to change the controller to accept params[:start_date]
and params[:end_date]
But I don't think I quite know how the pieces fit together to make this work. Guidance? Help?
Here is what I am trying now:
VIEW: find_start_end.html.erg
<% form_tag('return_search') do %>
<p>
<label>Start Date</label> <%= date_select('start_date', 'params') %>|
<label>End Date</label> <%= date_select :end_date, params[:end_date] %>
</p>
<p><%= submit_tag "Get Stats" %></p>
<% end %>
CONTROLLER:
def return_search
@sent_emails = ContactEmail.all(:conditions => ['date_sent >= ? and date_sent <= ?', params[:start_date], params[:end_date]])
@made_calls = ContactCall.all(:conditions => ['date_sent >= ? and date_sent <= ?', params[:start_date], params[:end_date]])
@letters_sent = ContactLetter.all(:conditions => ['date_sent >= ? and date_sent <= ?', params[:start_date], params[:end_date]])
@contacts_added = Contact.all(:conditions => ['date_entered >= ? and date_entered <= ?', params[:start_date], params[:end_date]])
respond_to do |format|
format.html #view needs to be the same name as the method
end
def find_start_end
end