我知道这是一个古老的问题,但我无法解决它.. 我想显示一个模式中的评论列表,每个迭代都是特定的。Rails:使用数据填充模态
内容的has_many注释,注释belongs_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作为模态中的整数,然后在模态内查询..但可能有点粗糙? – Werner