【发布时间】:2016-03-17 20:26:17
【问题描述】:
我正在尝试以模式显示评论者的用户个人资料。因此,当用户点击评论上方的“用户名”时,会弹出一个带有相应用户个人资料信息的模式。我尝试将 (comment.id) 参数传递给我的辅助方法,然后返回每个评论者的用户配置文件,我在模态视图中使用该配置文件。
我的助手:
def getuserprofileofcommenter(commentid)
specific_comment = Comment.where("id = ?", commentid)
specific_comment.each do |comment|
@commenter = Userprofile.find_by("id = ?", comment.userprofile_id)
end
end
我的模态(在视图中):
<div id="commenterModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
...
<div class="row">
<div class="col-sm-9">
<p style="font-weight: bold;"><%= @commenter.user_description %></p>
<p><%= @commenter.bio %></p>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">OK</button>
</div>
...
我的看法:
<%= link_to "username", getuserprofileofcommenter(comment.id), :class => "btn", :remote => false, "data-toggle" => "modal", "data-target" => "#commenterModal" %>
link_to 似乎将我的辅助方法作为路径。当我单击链接“用户名”时,会弹出一个模式,但会显示第一个评论者的个人资料,然后重定向到模式中的 comment_path。我似乎无法在模式中获得正确的用户个人资料信息。
任何建议将不胜感激!
【问题讨论】:
标签: ruby-on-rails twitter-bootstrap bootstrap-modal helper link-to