【发布时间】:2012-07-24 23:32:59
【问题描述】:
更新
我可以通过更改模型调用来使其正常工作
@comments = VideoComment.all(:conditions => { :video_id => @video.id}, :limit => 5, :order => :created_at)
@comments = VideoComment.last(5).reverse
它有效,但它为我提供了所有视频中的最后一个视频,而我只想要当前视频中的那些 (@video.id)。
关于如何做到这一点的任何线索?
我有一个Videocontroller 和一个VideoComments 控制器,用于管理Video 控制器的cmets。我试图让我的远程表单使用 ajax 更新 cmets 列表,但它似乎不起作用。你能找出我做错了什么吗?
展示页面的HTML代码:
- if current_user
#comment-form
= render 'video_comments/comment_form'
%ul
#comments
= render @comments
video_cmets/_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_Commentscontrollercreateaction:
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中的新评论吗?
标签: ruby-on-rails ruby ajax ruby-on-rails-3