如何使下拉菜单中的每个选项成为与 simple_form 调用关联的链接?
我使用 simple_form 插件创建了这个表单:
<%= simple_form_for([@video, @video.comments.new], :remote => true) do |f| %>
<%= f.association :comment_title, :collection => @video.comment_titles, :label => "Comment Title:", :include_blank => false %>
<%= f.input :body, :label => false, :placeholder => "Post a comment." %>
<%= f.button :submit, :value => "Post" %>
<% end %>
这会创建一个带有以下行的下拉列表:
<%= f.association :comment_title, :collection => @video.comment_titles, :label => "Comment Title:", :include_blank => false %>
我的问题是如何修改此代码,以便每个下拉项都是每个 comment_title
的链接个人表演视图?
更新
这是从第一个答案的代码生成的 html:
<select class="select optional" id="comment_comment_title_id" name="comment[comment_title_id]">
<option value="<a href=" comment_titles="" 224"="">#<CommentTitle:0x10353b890>">#<CommentTitle:0x10353b890></option>
<option value="<a href=" comment_titles="" 225"="">#<CommentTitle:0x1035296e0>">#<CommentTitle:0x1035296e0></option>
<option value="<a href=" comment_titles="" 226"="">#<CommentTitle:0x1035295a0>">#<CommentTitle:0x1035295a0></option>
</select>
I have this form using the simple_form plugin:
<%= simple_form_for([@video, @video.comments.new], :remote => true) do |f| %>
<%= f.association :comment_title, :collection => @video.comment_titles, :label => "Comment Title:", :include_blank => false %>
<%= f.input :body, :label => false, :placeholder => "Post a comment." %>
<%= f.button :submit, :value => "Post" %>
<% end %>
and this creates a drop down list with this line:
<%= f.association :comment_title, :collection => @video.comment_titles, :label => "Comment Title:", :include_blank => false %>
My question is how do you modify this code so that each drop down item is a link to each comment_title
's individual show view?
UPDATE
Here is the generated html from the code from the first answer:
<select class="select optional" id="comment_comment_title_id" name="comment[comment_title_id]">
<option value="<a href=" comment_titles="" 224"="">#<CommentTitle:0x10353b890>">#<CommentTitle:0x10353b890></option>
<option value="<a href=" comment_titles="" 225"="">#<CommentTitle:0x1035296e0>">#<CommentTitle:0x1035296e0></option>
<option value="<a href=" comment_titles="" 226"="">#<CommentTitle:0x1035295a0>">#<CommentTitle:0x1035295a0></option>
</select>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我其实已经想通了。这是 ruby 代码:
它将数组中的第一个元素作为文本传递,将数组中的第二个元素作为值传递。然后我使用这个 jQuery 代码:
非常简单。
I actually figured it out. Here is the ruby code:
This passes the first element in the array as the text, and the second element in the array as the value. Then I use this jQuery code:
Pretty simple.
尝试
:collection => @video.comment_titles.map {|ct| [ct, (link_to ct, comment_title_path(ct))] }
try
:collection => @video.comment_titles.map {|ct| [ct, (link_to ct, comment_title_path(ct))] }