【发布时间】:2016-07-27 16:36:28
【问题描述】:
我知道这是一个老问题,但我无法解决它.. 我想以特定于每次迭代的模态显示 cmets 列表。
内容has_many cmets,评论属于_to content`
@contents.each do |content|
content.title
button_to('read', category_modal_path(:comment_id => content.id), remote: true, :class=> 'modal-trigger2', 'data-target'=>'modal3')
end
控制器
def category_modal
@comments = Comment.online.where(content_id: params[:comment_id])
respond_to do |format|
format.js
end
模态
<div id="modal3" class="modal modal-fixed-footer">
...here I want show the list of comments
category_modal.js
$('#modal3').html(<%= j( render partial: 'shared/modal2', locals: {comments: @comments} )%> );
咖啡
$('.modal-trigger2').leanModal()
模态打开但没有数据..帮助会很好..
【问题讨论】:
-
您是否检查了 ajax 的响应?如果响应有一些数据。
-
我得到零。可能是我的方法是错误的。首先想到的是在模态中获取 content.id 作为整数,然后在模态中查询..但可能有点粗糙?
标签: ruby-on-rails ajax coffeescript modal-dialog