Reputation: 553
Using this post as guidance I am trying to create a link to the next comment on my comments show page. I am getting this error however:
undefined method `next' for #<Comment:0x00000103d59db0>
In my routes comments belong to posts:
resources :posts do
resources :comments
end
In my posts model I have this:
def next
post.comments.where("id > ?", id).order("id ASC").first
end
My comments controller:
@post = Post.find(params[:post_id])
@comment = Comment.find params[:id]
@commentnext = @post.comments.find(params[:id])
and then in my comments show view I have the link:
<%= link_to "Next Comment", post_comment_path(@post, @commentnext.next) %>
Upvotes: 0
Views: 51