Use dropdown selection to open a page with Ruby on Rails
Just looking for approach. I have a dropdown list for example (index, edit, new ). After selecting any of these and submitting the fo开发者_开发问答rm, I want to go to a particular page. Any ideas?
In your controller:
@addresses = {
:home => root_path,
:new_test => new_test_path,
:name => some_path
}
In your view:
<%= form_tag do %>
<%= select "link", "somewhere", @addresses %>
<%= submit_tag "Go", :id => "go" %>
<% end %>
In your application.js:
$("input[type='submit']#go").bind('click', function(event){
window.location = $("select#link_somewhere").val();
event.preventDefault();
})
That is in case you use jQuery. If you use prototype it's a bit different.
精彩评论