<%= 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);" %>
最佳答案
options_from_collection_for_select 创建如下 erb 代码:
<option value="#{profile.id}">#{profile.profile_blip}</option>
在模型类“Profile”中编写一个方法,该方法返回您想要的内容。然后将 select_tag 更改为:
<%= select_tag "profile", options_from_collection_for_select(@profile, "new_method_name",'profile_blip'),:onchange => "window.location.replace('/'+this.value);" %>
关于javascript - Ruby on Rails : How to add a link_to in a select_tag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33364423/