I’m using Rails and jqPlot to display some data on a webpage. The graph needs to be flexible by date (as in, the user can select a time range, and the graph will update itself). Here’s my code so far (in my View):
<%= form_tag home_event_trends_path(params[:timePeriod]), :method => 'post' do %>
<p>
<%= select_tag :timePeriod, options_for_select(["2 Hours Ago", "1 Week Ago", "3 Months Ago"], :selected => params[:timePeriod]) %>
<%= submit_tag "Refresh", :name => nil %>
</p>
<% end %>
Home is my controller, event_trends is an action, I suppose. (The path is localhost:3000/home/event_trends.3102030)
This works fine. However, I need to also pass another parameter to my controller. This webpage is already having a parameter passed to it, params[:format] (this is the 3102030 in the URL, which changes based upon what event I want to display), and I need this passed along as well. I’ve tried:
home_event_trends_path(params[:timePeriod][:format])
home_event_trends_path(params[:timePeriod],[:format])
home_event_trends_path(params([:timePeriod][:format]))
among others.
How do I get my controller to see multiple parameters from my View?
Nothing against Idan’s answer, but this was what I ended up doing (for future Googlers…)
In my View:
And then in my Home Controller:
And finally, the Model:
This seems to work best for me. I decided to allow the URL to change for the GET request, and I’m immediately storing the
issueparameter in the search box, for use later on.Hope this helps anyone in the future!