Created
April 7, 2017 10:37
-
-
Save WaKeMaTTa/0717d354fa3d428cec6b0be4a8b7664b to your computer and use it in GitHub Desktop.
Use alias_method for better readability
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/policies/application_policy.rb | |
class ApplicationPolicy | |
attr_reader :user, :record | |
def initialize(current_user, record) | |
@user = user | |
@record = record | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/policies/post_policy.rb | |
class PostPolicy < ApplicationPolicy | |
alias_method :post, :record | |
def update? | |
post.user == user | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment