我知道這是一個古老的問題,但我無法解決它.. 我想顯示一個模式中的評論列表,每個迭代都是特定的。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