arinthros said almost 4 years ago on Nested Comments from Scratch :
Is there a simple way to limit nesting to one or two levels deep?

azback5 said over 2 years ago on Nested Comments from Scratch :
I've been trying to add a feature here where we can also EDIT our comments. 

In comments controller I have added:

  def edit
      @comment = @commentable.comments.find(params[:id])
    end

    def update
       @comment.update!(comment_params)
       redirect_back(fallback_location: root_url)
       render "edit"
    end

__________________________________

And in our views _comment.html.erb partial i added in the div 'links'

<%= link_to 'Edit', [:edit, comment.commentable, comment] %>

__________________________________________________________

I am confused what to populate the edit.html.erb file with. Do you have any suggestions?

Thanks


David Kimura PRO said over 2 years ago on Nested Comments from Scratch :
  Since the edit link_to  isn't a remote: true, you would be rendering a new view. You might be able to render the comment form within there. If you want it to be a bit more of an SPA feel, you could use the remote: true and then that would render the edit.js.erb where you can then render the form partial and display a modal.

If you want to make it load a new page to edit the comment, then you would need to render the form.

azback5 said over 2 years ago on Nested Comments from Scratch :
thanks for your help! 

I'm a rookie with javascript and I'm eager to learn it, so I feel obliged to ask...

How would you go about writing the JS to render the form partial and display a modal? 

(Great tutorial by the way, I've been teaching myself and this helped me a great deal)



David Kimura PRO said over 2 years ago on Nested Comments from Scratch :
  You can check out this episode and the Part 1 of it as well. It uses jquery, but the same could be accomplished with vanilla JS if you're using something like Bootstrap 5 Alpha.


azback5 said over 2 years ago on Nested Comments from Scratch :
Thanks, I'll check this out.

AhmedNadar PRO said about 2 years ago on Nested Comments from Scratch :
Thanks for your video. 
I have followed it but I got an error on creating a reply. I'm able to create a comment and delete a reply. 
I get below error header + previous comment when I create a reply. Although when I refresh item show view i see all replies.

NoMethodError at /comments/12/comments
undefined method `comment_url' for #<Comments::CommentsController:0x00000000025e18>
Did you mean?  comment_comment_url
URL
http://localhost:3000/comments/9/comments



Better_errors request info and instance variables
@_params | #<ActionController::Parameters {"authenticity_token"=>"======", "comment"=>
#<ActionController::Parameters {"content"=>"nice"} permitted: false>, "commit"=>"Create Comment", "controller"=>"comments/comments", "action"=>"create", "comment_id"=>"10"} permitted: false>
@ransack_items | Ransack::Search<class: Item, base: Grouping <combinator: and>>
@commentable | #<Comment id: 10, user_id: nil, commentable_type: "Comment", commentable_id: 9, content: nil, created_at: "-0000", updated_at: "20000">
@current_user | #<User id: 1, email: "admin@gmail.com", created_at: "0000", updated_at: "0000-", first_name: "Admin", last_name: "Man", slug: "admin-man">
@comment | #<Comment id: 12, user_id: 1, commentable_type: "Comment", commentable_id: 10, content: "nice", created_at: "-0000", updated_at: "0000">
Request parameters | {"authenticity_token"=>"=====", "comment"=>{"content"=>"nice"}, "commit"=>"Create Comment", "controller"=>"comments/comments", "action"=>"create", "comment_id"=>"10"}

While I followed your video, I have different setup for items:
#controllers/items/comments_controller.rb
@commentable = Item.friendly.find(params[:item_id])

#routes.rb
resources :items do
 resources :comments, only: %i[new create destroy], module: :items
end

What am I missing? 
Thanks

David Kimura PRO said almost 2 years ago on Nested Comments from Scratch :
  It looks like your instance variable commentable got set to a Comment instance instead of an Item. Do you have the app set up for a comment to receive a comment? And when you set the commentable, you should likely be passing in the Item instead of the Comment.

Login to Comment