作者:michael | 来源:互联网 | 2023-02-01 21:20
Iammakingsitewithvideos.Eachvideocouldbecommentedinshow.html.erb.Becausenumberofcomm
I am making site with videos. Each video could be commented in show.html.erb. Because number of comments could be big I made pagination for comments using will_paginate. When creating/deleting new comments I want to update comments list and pagination bar. I can't manage comments and pagination to be updated remotely and to work well.
我正在制作带有视频的网站。每个视频都可以在show.html.erb中注释。因为评论的数量可能很大,所以我使用will_paginate对评论进行了分页。在创建/删除新评论时,我想更新评论列表和分页栏。我无法管理评论和分页,以便远程更新并运作良好。
My model
class Video 0, :less_than_or_equal_to => 1000000}
validates_uniqueness_of :src
validates :name, presence: true
validates :src, presence: true
after_initialize :init
def init
self.rating ||= 0 #will set the default value only if it's nil
end
end
I have view videos/show.html.erb
我有观看视频/ show.html.erb
Name: <%= @video.name %>
Description: <%= @video.description %>
I have partial comments/_form.html.erb
我有部分评论/ _form.html.erb
<%if @user%>
<%= form_for([@video.user, @video, @video.comments.build], remote: true) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label "Сообщение" %>
<%= f.text_field :body %>
<%= submit_tag "Добавить сообщение", class: "btn btn-large btn-primary" %>
<% end %>
<%end%>
My comments/_comment.html.erb
<%if comment.user%>
<%= comment.user.name %> (создано <%= time_ago_in_words(comment.created_at) %> назад):
<%end%>
<%= comment.body %>
<%if comment.user == current_user%>
<%= link_to "Удалить сообщение", [comment.video.user, comment.video, comment],
:cOnfirm=> "Уверен?",
:method => :delete, remote: true %>
<%end%>
I have controller controllers/comments_controller.rb
我有控制器控制器/ comments_controller.rb
class CommentsController
I have comments\create.js.erb
我有评论\ create.js.erb
$("#comments_form").html("<%= escape_Javascript(render :partial => "comments/comment",
:collection => @comments) %><%= escape_Javascript(will_paginate @comments) %>")
Everything is almost great: my new comment is created, my pagination bar is updated, but links instead of /users/1/videos/17?page=1 are /users/1/videos/17/comments?page=1 I tried hard for two days to find out how to fix this problem, but no use...
一切都很棒:我的新评论已创建,我的分页栏已更新,但是链接而不是/ users / 1 / videos / 17?page = 1是/ users / 1 / videos / 17 / comments?page = 1我试过了很难两天找出如何解决这个问题,但没有用......
1 个解决方案