Rails:从选择标记中获取值

时间:2013-06-07 14:04:23

标签: ruby-on-rails

<%= form_tag 'select_domain', :url => administer_admin_domain_path(:id), :method => :get do %>
    <%= select_tag "id", options_from_collection_for_select(@domains, :id, :caption), :onchange => "this.form.submit();" %>
<% end %>

我希望选中的选项ID在我提交的表单的URL中是:id,这可能吗?

1 个答案:

答案 0 :(得分:0)

怎么样:

<%= form_tag 'select_domain', :url => administer_admin_domains_path, :method => :get do %>

 <%= select_tag "id", options_from_collection_for_select(@domains, :id, :caption), :onchange=>"this.form.action=this.form.action + '/' + this.value; this.form.submit(); %>

<% end %>

我没有测试代码。只是给你一些可能有帮助的想法。 :)