Home>
Added a function to comment on a post on the post details page.
Then add the delete comment function and press delete
ActiveRecord :: RecordNotFound in TweetsController # destroy
Couldn't find Tweet with 'id' = 27
I get an error.
You are in the destroy action of tweets.controller.rb.
I would like to skip to comments.controller.rb's destroy ...
What should I do?
file views/commets/comment.html.haml
.comments
% h4<Comment list>
-if @comments
[email protected] comments.each do | comment |
% p
% strong
= link_to comment.user.nickname, "/users/#{comment.user_id}"
:
= comment.text
-if user_signed_in?&¤t_user.id == comment.user_id
= link_to "delete", "/ tweets/# {comment.id}", method:: delete, class: "image-delete"
file controllers/comments_controller.rb
class CommentsController</pre>
<pre><code>file routes.rb
resources: tweets do
resources: comments, only: [: create,: destroy]
end
-
Answer # 1
-
Answer # 2
= link_to" delete ","/comments/# {comment.id} ", method:: delete , class: "image-delete"
Commets plural toFile name
resources: tweets do
resources: comments, only: [: create]
end
resources: comments, only: [: destroy]Remove from nesting
def destroy
comment = Comment.find (params [: id])
comment.destroy
redirect_to tweets_path
endAdd redirect_to
This will clear all errors
Related articles
- ruby - when deleting a post, i want to delete the comment associated with the model together
- ruby - if you try to delete a comment post, you will get an error `destroy' for nil:nilclass please solve it
- ruby - like nomethoderror that occurred after implementing the function
- ruby - data is not stored when implementing the comment function
- ruby - rails tutorial chapter 13 delete does not work in the test of increasing/decreasing the number of posts with rspec
- delete after vba specific characters
- ruby on rails - [rails] i want to dynamically add and delete forms using cocoon
- ruby on rails - rails not updated after editing update
- ruby - rails:loaderror occurs after rails s
- ruby - i want to establish the pagination function after separating the rails method
- ruby on rails 6 - after updating, it becomes no route matches [post] "/ posts/2/edit"
- i want to delete the files that i got after mget by ftp
- ruby on rails 5 - after overwriting the image under assets, nothing is displayed
- ruby - when saving the value after submitting
- ruby - isn't it possible to submit again after submitting with one click?
- ruby - i get a routing error when i delete
- ruby - about errors after deploying heroku
- java - i want to delete the hamburger menu after jumping to the link in the page
- error when implementing search function using ransack in ruby on rails
- ruby - (fixed) after deploying, i can't open the rails app in production
Related questions
- ruby - passing variables using render partial
- ruby - i would like to know how to realize what is written in smarthr's blog
- ruby - i installed carrierwave with rails, but i can't see the image
- ruby - about rails controller new action
- ruby - rails page does not open
- [ruby] i'm having trouble with nomethoderror
- ruby - [search function] acquisition of products associated with users
- ruby - even if each statement is used, the contents of the db cannot be displayed in order and an error occurs
- ruby - if i include the'omniauth-facebook'gem, do i need to install the'omniauth' gem as well?
- ruby - unable to open rails server
= link_to "delete", "/ tweets/# {comment.id}", method:: delete, class: "image-delete"
is "/ tweets. Please change it to comments.