rubocop corrections
This commit is contained in:
parent
c63c6bc448
commit
de29815686
72 changed files with 468 additions and 311 deletions
|
@ -1,3 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Base for application controllers
|
||||
class ApplicationController < ActionController::Base
|
||||
helper_method :current_user
|
||||
helper_method :logged_in?
|
||||
|
@ -5,7 +8,7 @@ class ApplicationController < ActionController::Base
|
|||
def current_user
|
||||
User.find_by(id: session[:user_id])
|
||||
end
|
||||
|
||||
|
||||
def logged_in?
|
||||
!current_user.nil?
|
||||
end
|
||||
|
@ -13,15 +16,13 @@ class ApplicationController < ActionController::Base
|
|||
protected
|
||||
|
||||
def notices_from_errors(record)
|
||||
messages = record.errors.messages.map do |attribute, messages|
|
||||
errors = record.errors.messages.map do |attribute, messages|
|
||||
messages.map { |message| "#{attribute} #{message}".capitalize }
|
||||
end
|
||||
messages.flatten
|
||||
errors.flatten
|
||||
end
|
||||
|
||||
def ensure_admin
|
||||
unless current_user&.admin?
|
||||
redirect_to '/welcome', notice: 'You are not allowed to perform this action'
|
||||
end
|
||||
redirect_to '/welcome', notice: 'You are not allowed to perform this action' unless current_user&.admin?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue