I want to give edit and delete permissions only to the poster

version

・ Ruby 2.5.7 ・ Rails 5.2.4.3

I want to give edit and delete permissions only to the poster

CRUD processing is done! However, at this rate, all posts can be edited or deleted. I want to make edit and delete permissions only for posters. スクリーンショット 2020-08-07 11 24 11

Use the following methods to protect user posts

unless means if it wasn't. In the following, If the ID of the received user does not match the ID of the logged-in user (current_user), it means that the process will not be executed and the redirect will be returned. スクリーンショット 2020-08-07 11 33 46

Call the method with before_action and you're done! !! !!

before_action is the one that is executed before all the actions of the controller are executed. This time I want to do it only for editing and deleting, so I only edit, update and destroy. スクリーンショット 2020-08-07 11 33 58

Recommended Posts

I want to give edit and delete permissions only to the poster
[Ruby] I want to extract only the value of the hash and only the key
I want to display the name of the poster of the comment
I want to add a delete function to the comment function
I want to bring Tomcat to the server and start the application
I want to call a method and count the number
I want to give a class name to the select attribute
In Java, I want to trim multiple specified characters from only the beginning and end.
I want to return to the previous screen with kotlin and java!
[Ruby] I want to output only the odd-numbered characters in the character string
[Active Admin] I want to customize the default create and update processing
I want to pass the argument of Annotation and the argument of the calling method to aspect
I want to output the day of the week
I want to var_dump the contents of the intent
I want to truncate after the decimal point
I want to delete files managed by Git
I want to get the value in Ruby
I want to control the start / stop of servers and databases with Alexa
Development memo ~ I want to display only the first image posted multiple times ~
I want to get only the time from Time type data ...! [Strftime] * Additional notes
I want to recursively get the superclass and interface of a certain class
[Java] I want to calculate the difference from the date
I want to embed any TraceId in the log
I want to see only the latest because the Docker log has become too large
I want to morphologically analyze the log in the DB and put it in the DB to classify messages 1
I want to judge the range using the monthly degree
I want to know the answer of the rock-paper-scissors app
I want to dark mode with the SWT app
I want to apply ContainerRelativeShape only to specific corners [SwiftUI]
I want to transition screens with kotlin and java!
I want to call the main method using reflection
[Rough commentary] I want to marry the pluck method
I want to be aware of the contents of variables!
I want to return the scroll position of UITableView!
I want to simplify the log output on Android
I want to get a list of the contents of a zip file and its uncompressed size
I want to set the video playback time (HH: MM: SS) to seconds, and vice versa.
I want to set the conditions to be displayed in collection_check_boxes
[Rails] [bootstrap] I want to change the font size responsively
I tried to summarize the basics of kotlin and java
I want to use screen sharing on the login screen on Ubuntu 18
(´-`) .. oO (I want to easily find the standard output "Hello".
I want to expand the clickable part of the link_to method
I want to change the log output settings of UtilLoggingJdbcLogger
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
[jackson] I want to receive JSON values "0" and "1" as boolean
I want to use the Java 8 DateTime API slowly (now)
I want to create a form to select the [Rails] category
I want to use the sanitize method other than View.
I want to put the JDK on my Mac PC
I want to recursively search the class list under the package
I want to distinct the duplicated data with has_many through
I want to transition to the same screen in the saved state
I want to implement various functions with kotlin and java!
I want to narrow down the display of docker ps
I want to return multiple return values for the input argument
[Ruby] I want to reverse the order of the hash table
I want to temporarily disable the swipe gesture of UIPageViewController
I want to pass the startup command to postgres with docker-compose.
I want to simplify the conditional if-else statement in Java