ruby on rails - nested attribute pagination error (kaminari) -


I'm pretty sure this is a simple fix but I'm not seeing it. I have an app where I want to show a music_video comment. Below are my controllers:

  def show @music_video = MusicVideo.find (params [: id]) @comment = Comment.new @comments = @ music_video.comments.page (params [: page ]). Copy (3) end  

The above is my music video controller.

  def @music_video = MusicVideo.find (params [music_video_id]) @comment = @ music_video.comments.build (comment_params) if @ comment.save flash [: notice] = "Submit Comment Removed "redirect_to music_video_path (@music_video) and then delete 'music_videos / show' end end def @comment = comment .ind (params [: id]) @ comment.destroy redirect_to root_path, notice:" comment deleted " End personalized DF comment. Ultimate Parameters.Require (comment.) Clear (: body) end  

My comments above is the controller

Finally my show page:

  & lt; Div class = "comments_row" & gt; & Lt;% @ music_video.comments.each do | Comment | & Gt%; & Lt;% If user_signed_in? & Amp; & Amp; Current_user.admin? & Gt%; & Lt; P class = "comment" & gt; & Lt;% = comment.body% & gt; & Lt; / P & gt; & Lt;% = link_to 'Delete comment', music_video_comment_path (@ music_video, comment), method :: delete% & gt; & Lt;% else% & gt; & Lt; P class = "comment" & gt; & Lt;% = comment.body% & gt; & Lt; / P & gt; & Lt;% end% & gt; & Lt;% end% & gt; & Lt; / Div & gt; & Lt;% = Pagnetate @ comments% & gt;  

I'm pretty sure there is something wrong with my controllers, but I'm not sure what this is really about. @comments is right within the correct CURD operation (Show) in Controller (MusicVideo). Currently I have six comments in a special show page and it is okay to mark the page but six comments are not endorsed any thoughts?

Edit -------------

I understood a problem, but stumbled upon a new one. I came to know that in my controller I am declaring @comments = pagination and so on etc. There is no @ comment to be endorsed in my thoughts. The problem is that when I type

  & lt;% = paginate @ comment% & gt;  

The code will break. The problem is now that what I'm doing is the paginate variable. The effort of this code will also be broken

  & lt;% = paginate @ music_video.comments% & gt;  

Any recommendations?

Camerari gem for pager This is what my My Music Video Controller's Show Action looks like:

  def show @music_video = MusicVideo.find (params [: id]) @comments = @ music_video.comments.page (params [: pg]). Copy (3) end  

and here my show scene looks like this:

  & lt; P id = "notice" & gt; & Lt;% = Notice% & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Strong> Name: & lt; / Strong> & Lt;% = @ music_video.name% & gt; & Lt; / P & gt; & Lt;% @ comments.each do | Comment | & Gt%; & Lt; P & gt; Comment: & lt;% = comment.text% & gt; & Lt; / P & gt; & Lt;% end% & gt; & Lt;% = Pagnetate @ comments% & gt; & Lt;% = link_to 'edit', edit_music_video_path (@music_video)%> | & Lt;% = link_to 'back', music_feed_path% & gt;  

This is working and I'm looking for points on the page.

I think one thing I am direct watching is that you and <% lt;% @comments .each do it. Comment | % & Gt; Instead of & lt;% @ music_video.comments.each do | Comment | % & Gt; Because as you have it now, it will display all the comments for the video, regardless of which page you are on. If you had 6 comments and had 3 pages per page, you would see endorsement with two pages because you are running your coding on the basis of @comments and you have all 6 comments on both pages Can see Because you are doing .each with @ music_videos.comments.each .

Therefore, using at least @comments will be a start at both places and make sure that you are using. If you use it in your controller and see what do you get? Apart from this, Ryan Bates also has a good screencast on the Kabanadi: (That site is a great resource for railway questions)

/ P>

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -