Module: Cally::Methods
- Included in:
- ApplicationController
- Defined in:
- lib/cally/methods.rb
Instance Method Summary collapse
- #admin_or_same_user? ⇒ Boolean
- #logged_in_as_admin? ⇒ Boolean
- #same_user? ⇒ Boolean
- #set_mailgun_prefix ⇒ Object
- #test_env? ⇒ Boolean
Instance Method Details
#admin_or_same_user? ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cally/methods.rb', line 31 def admin_or_same_user? # checks if the user loggedin is the same user requesting the action # or the user is administrator if logged_in? && (current_user == @user || current_user.admin) return true else flash[:error] = 'You can only perform this action as your own or an admin account.' if logged_in? redirect_to cally.user_path(current_user) else redirect_to cally.login_path end end end |
#logged_in_as_admin? ⇒ Boolean
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cally/methods.rb', line 16 def logged_in_as_admin? # checks if the loggedin user has administrator rights if logged_in? && current_user.admin return true else flash[:error] = 'You need to be admin for this action.' if logged_in? redirect_to cally.user_path(current_user) else redirect_to cally.login_path end return false end end |
#same_user? ⇒ Boolean
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/cally/methods.rb', line 5 def same_user? # checks if the loggedin user is the same as the user requesting this action if logged_in? && current_user == @user return true else flash[:error] = 'You can only view your own profile.' redirect_to cally.login_path return false end end |
#set_mailgun_prefix ⇒ Object
54 55 56 |
# File 'lib/cally/methods.rb', line 54 def set_mailgun_prefix @mailgun_prefix = ENV['MAILGUN_PREFIX'] || 'cally/' end |
#test_env? ⇒ Boolean
46 47 48 49 50 51 52 |
# File 'lib/cally/methods.rb', line 46 def test_env? if Rails.env.development? || Rails.env.production? return false else return true end end |