Abuse of protected in guides

This commit is contained in:
Akira Matsuda 2016-12-23 20:17:32 +09:00
parent d1daf4c313
commit 0e109c8710
3 changed files with 5 additions and 5 deletions

View File

@ -62,7 +62,7 @@ module ApplicationCable
self.current_user = find_verified_user
end
protected
private
def find_verified_user
if current_user = User.find_by(id: cookies.signed[:user_id])
current_user

View File

@ -36,7 +36,7 @@ class User < ApplicationRecord
before_validation :ensure_login_has_a_value
protected
private
def ensure_login_has_a_value
if login.nil?
self.login = email unless email.blank?
@ -66,7 +66,7 @@ class User < ApplicationRecord
# :on takes an array as well
after_validation :set_location, on: [ :create, :update ]
protected
private
def normalize_name
self.name = name.downcase.titleize
end
@ -77,7 +77,7 @@ class User < ApplicationRecord
end
```
It is considered good practice to declare callback methods as protected or private. If left public, they can be called from outside of the model and violate the principle of object encapsulation.
It is considered good practice to declare callback methods as private. If left public, they can be called from outside of the model and violate the principle of object encapsulation.
Available Callbacks
-------------------

View File

@ -827,7 +827,7 @@ NOTE: A frequent practice is to place the standard CRUD actions in each
controller in the following order: `index`, `show`, `new`, `edit`, `create`, `update`
and `destroy`. You may use any order you choose, but keep in mind that these
are public methods; as mentioned earlier in this guide, they must be placed
before any private or protected method in the controller in order to work.
before any private method in the controller in order to work.
Given that, let's add the `show` action, as follows: