Ruby On Rails:如何在select_tag中添加link_to

时间:2015-10-27 09:41:29

标签: javascript html ruby-on-rails

 <%= select_tag "profile", options_from_collection_for_select(@profile, 'id','profile_blip'),:onchange => "window.location.replace('/'+this.value);" %>

到位'id'想要放置一些链接是否可以在rails中
我正在尝试下面的代码没有得到,请帮帮我。

<%= select_tag "profile", options_from_collection_for_select(@profile, "profile/publications",'profile_blip'),:onchange => "window.location.replace('/'+this.value);" %>

1 个答案:

答案 0 :(得分:2)

options_from_collection_for_select创建一个这样的erb代码:

<option value="#{profile.id}">#{profile.profile_blip}</option>

在模型类中编写方法&#34; Profile&#34;返回你想要的东西。然后将select_tag更改为:

<%= select_tag "profile", options_from_collection_for_select(@profile, "new_method_name",'profile_blip'),:onchange => "window.location.replace('/'+this.value);" %>