bookstore/app/controllers/application_controller.rb
2021-03-21 17:02:04 +01:00

19 lines
437 B
Ruby

class ApplicationController < ActionController::Base
helper_method :current_user
helper_method :logged_in?
def current_user
User.find_by(id: session[:user_id])
end
def logged_in?
!current_user.nil?
end
def notices_from_errors(record)
messages = record.errors.messages.map do |attribute, messages|
messages.map { |message| "#{attribute} #{message}".capitalize }
end
messages.flatten
end
end