Hi,
I’m trying to create a select box with an onchange event. When onchange
is fired, I want to redirect to a nested rest url. The problem is that I
don’t know how to pass the selected value to the url:
Any suggestions?
Hi,
I’m trying to create a select box with an onchange event. When onchange
is fired, I want to redirect to a nested rest url. The problem is that I
don’t know how to pass the selected value to the url:
Any suggestions?
Maarten P. wrote:
Hi,
I’m trying to create a select box with an onchange event. When onchange
is fired, I want to redirect to a nested rest url. The problem is that I
don’t know how to pass the selected value to the url:Any suggestions?
I did this recently by creating a RESTful RedirectionsController. I
wanted a select box to redirect me to a #new action.
map.resources :redirections
map.resources :activities do |map|
map.resources :exercises, :name_prefix => ‘’
end
<% form_tag(redirections_path, :method => :post) do %>
<%= select “exercise”, “activity_id”, Activity.find(:all).collect
{|act| [ act.name, act.id ] } %>
<%= hidden_field_tag ‘redirection’, ‘new_exercise’ %>
<%= submit_tag “Add a new exercise for this activity” %>
<% end %>
class RedirectionsController < ApplicationController
def create
case params[:redirection]
when ‘new_exercise’
redirect_to new_exercise_path(params[:exercise][:activity_id])
else
raise ArgumentError
end
end
end
The idea is that you POST a string in params[:redirection], and an ID
that tells is where to redirect to. This could be DRYer, but it’s a big
improvement from the alternative (hardcoding your routes in your views
or somesuch).
Hope this helps.
Chris K.
http://kampers.net
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs