将URL参数传递给下拉列表

时间:2012-11-04 07:55:21

标签: ruby-on-rails forms url simple-form

我有一个简单的表格:

 <%= f.input :type, :required => true, :collection => ["Nonprofit","School","Company"], :hint => "Note: nonprofits will need to provide proof of nonprofit status", :input_html => { :value => params['type'] } %>
 <%= f.input :name, :label => "Organization" %>
 <%= f.input :first_name  %>
 <%= f.input :last_name %>
 <%= f.input :email %>

用户通过http://www.website.com/org/signup?type=Company

等网址访问此页面

我可以使用此格式在名称或电子邮件等字段中输入值,但无法弄清楚如何将参数传递给下拉列表。

我已经尝试了一些方法,包括将:value更改为:selected或:option但似乎没有任何效果。

1 个答案:

答案 0 :(得分:1)

好吧,想通了!在此发布以供将来使用。

<%= f.input :type, :required => true, :collection => ["Nonprofit","School","Company"], :hint => "Note: nonprofits will need to provide proof of nonprofit status", :selected => params['type'] %>

诀窍是删除:input_html部分,然后使用

:selected = > params['type']

希望将来帮助某人!