【问题标题】:Passing URL Parameter to Drop Down将 URL 参数传递给下拉菜单
【发布时间】:2012-10-24 09:33:04
【问题描述】:

我有一个简单的表格:

 <%= 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 但似乎没有任何效果。

【问题讨论】:

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


    【解决方案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']
    

    希望对未来的人有所帮助!

    【讨论】: