UPDATERuby on Rails的远程形成不更新页面
我已经奶源得到它通过改变从
@comments = VideoComment.all(:conditions => { :video_id => @video.id}, :limit => 5, :order => :created_at)
@comments = VideoComment.last(5).reverse
它的工作原理模型调用的工作,但它给我的最后一个视频评论从全部的视频,而我只想从当前的视频(@video.id
)。
任何线索如何做到这一点?
我有一个Video
控制器和VideoComments
控制器,它管理的Video
控制器的意见。我试图让我的远程表单用ajax更新评论列表,但它似乎不起作用。你能找到我做错了什么吗?显示页面的
HTML代码:
- if current_user
#comment-form
= render 'video_comments/comment_form'
%ul
#comments
= render @comments
video_comments/_comment_form.html.haml
= form_for current_user.video_comments.build(:video_id => params[:id]), :remote => true do |f|
.form-fields
.comment-content
= f.text_area :content, rows:2
= f.hidden_field :video_id
= f.hidden_field :user_id
.submit-form
= f.submit "Add a comment", :class => "btn btn-default "
的Video_Comments
控制器create
行动:
def create
@comment = VideoComment.create(params[:video_comment])
@video = @comment.video
@comments = VideoComment.all(:conditions => { :video_id => @video.id}, :limit => 5, :order => :created_at)
render :toggle
end
的toggle.js.erb
文件,该文件管理页面更改:
$("#comment-form").html("<%= escape_javascript render 'comment_form' %>");
$("#comments").html("<%= escape_javascript render @comments %>");
是'@ comments'新的评论? – 2012-07-25 00:05:52