开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜