URL : /evaluations
I have made a form to select a specific item (a period)
class EvaluationsController < ApplicationController
def index
@periods = Period.all
end
My form :
<% form_for XXXXX do %>
<%= collection_select(:period, :period_id, @periods, :id, :fullname) %>
<%= submit_tag("Valider") %>
<% end %>
I would like the form to go to /evaluations/3 when submited (if the selected period is 3).
When I go manually to /evaluations/3 it works like a charm but I really don’t know how to write the form_for to go the right url by submitting the form.
Simple way
Submit period ID to process data, and then redirect to action, which handles
evaluations/:idwith:idas parameters.This should do the trick.
Not so simple way
If you want to change something dynamically on your page after data was submitted – call method and respond with javascript
In javascript response you can put whatever you want – simple redirects or script, which will change page dynamically. It’s up to you.
Hope it helps.