简体   繁体   中英

Ruby On Rails : How to add a link_to in a select_tag

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

In place 'id' want to place some link is it possible in rails
I am trying with below code not getting, please help me out.

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

options_from_collection_for_select create a erb code like this:

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

Write a method in the model class "Profile" which returns what you want. Then change the select_tag to this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM