Module: CurrentUser::Controller::Helpers
- Defined in:
- lib/current_user/controller/helpers.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate_user! ⇒ Object
- #current_user ⇒ Object
- #sign_in(user) ⇒ Object
- #sign_out ⇒ Object
- #signed_in? ⇒ Boolean
Class Method Details
.included(base) ⇒ Object
4 5 6 7 |
# File 'lib/current_user/controller/helpers.rb', line 4 def self.included(base) base.hide_action %w(authenticate_user! current_user sign_in sign_out signed_in? user_signed_in?) base.helper_method %w(current_user signed_in? user_signed_in?) end |
Instance Method Details
#authenticate_user! ⇒ Object
9 10 11 12 13 14 |
# File 'lib/current_user/controller/helpers.rb', line 9 def authenticate_user! if current_user.nil? store_location end end |
#current_user ⇒ Object
16 17 18 19 20 |
# File 'lib/current_user/controller/helpers.rb', line 16 def current_user user_id = session[::CurrentUser::USER_SESSION_KEY] ::User.find_by_id user_id end |
#sign_in(user) ⇒ Object
22 23 24 |
# File 'lib/current_user/controller/helpers.rb', line 22 def sign_in(user) session[::CurrentUser::USER_SESSION_KEY] = user.id end |
#sign_out ⇒ Object
26 27 28 |
# File 'lib/current_user/controller/helpers.rb', line 26 def sign_out session[::CurrentUser::USER_SESSION_KEY] = nil end |
#signed_in? ⇒ Boolean
30 31 32 |
# File 'lib/current_user/controller/helpers.rb', line 30 def signed_in? current_user.present? end |