Home>
The comment function is being implemented.
Other users can also delete the comments that they have commented on.
I want to be able to delete only the comments I wrote
<% if c.user%>
I tried to do it, but I can't put a limit on it.
Besides,<% if c.user_id%>
I tried it, but it didn't change. I would like to know.
I look forward to working with you.
posts/show.html
<p>Comment list</p>
<% @ comments.each do | c |%>
<% unless c.user.blank?%>
">
<% end%>
<% = c.user.name unless c.user.blank?%>
<br />
<% = c.content%>
<% if c.user%>
<% = link_to "delete", comment_path (c), method:: delete, class: "comment-menus"%>
<% end%>
<br />
posts_controller
def index
@posts = Post.all.order (created_at :: desc)
end
def show
@post = Post.find_by (id: params [: id])
@user = @ post.user
@post = Post.find (params [: id])
@comments = @ post.comments
@comment = Comment.new
end
def new
@post = Post.new
end
def create
@post = Post.new (
content: params [: content],
user_id: @ current_user.id,
)
if params [: post] .present?
@ post.video = params [: post] [: video]
print params
end
if @ post.save
flash [: notice] = "Created a post"
redirect_to ("/ posts/index")
else else
render ("posts/new")
end
end
def edit
@post = Post.find_by (id: params [: id])
end
def update
@post = Post.find_by (id: params [: id])
@ post.content = params [: content]
if @ post.save
flash [: notice] = "Edited post"
redirect_to ("/ posts/index")
else else
render ("posts/edit")
end
end
def destroy
@post = Post.find_by (id: params [: id])
@ post.destroy
flash [: notice] = "Post deleted"
redirect_to ("/ posts/index")
end
def ensure_correct_user
@post = Post.find_by (id: params [: id])
if @ post.user_id! = @ current_user.id
flash [: notice] = "You are not authorized"
redirect_to ("/ posts/index")
end
end
end
-
Answer # 1
-
Answer # 2
I don't know what the controller looks like, but how about this description?
<% if c.user_id == current_user.id%>
Related articles
- ruby - [rails] i want to implement a function to exclude (unlink) group participants
- ruby on rails - with the product listing function, an error message appears only for the product description
- ruby on rails - i can't implement the rails like function
- ruby on rails - i want to implement a report function, but i get an actioncontroller :: urlgenerationerror
- ruby - rails pagination function i want to display in alphabetical order
- ruby - [rails] the cart function cannot get the cart id associated with the user
- ruby on rails - i want to implement a function that returns a line bot stamp
- ruby - about the delete function in rails
- ruby on rails - how to implement a sort function by the value of the statistical column that aggregates the values of related
- ruby on rails - [rails] i want to implement a filtering function and display the corresponding items on the list screen
- ruby on rails - [rails] chat function is being implemented jserb file cannot be read
- ruby on rails 6 - [rails]'unfollow' function does not work * no error message
- ruby - post photo&like function on rails self-introduction page
- ruby on rails - i want to implement a function for administrator users to register luggage for general users in rails
- ruby on rails - i want to implement a function (destroy action) that can delete posted messages, but i am getting an active reco
- ruby on rails - cart function routing error cannot be resolved
- ruby - [rails] implementation of search function
- ruby on rails - implementation of validation function
- ruby on rails - [rails] i'm implementing a search function using form_with, but i'm having trouble with the search results not b
Related questions
- ruby - sass :: syntaxerror on rails s
- javascript - i want the scroll bar to always appear at the bottom of the chat screen
- ruby - i want to use two rails renders
- ruby - the top screen is displayed at http: // localhost: 3000/users/sign_in
- ruby - [rails] the class attribute specified by the div tag enclosed in simple_format is not applied
- ruby on rails sorting
- html - i can't set the regular expression well
- ruby - rails i want to make the created_at time the same when creating multiple data at once
- ruby - dynamic form implementation in nested_form
Excuse me
<% if c.user == current_user.id%>
I solved it here!
Thank you!