bookstore/app/controllers/application_controller.rb

20 lines
437 B
Ruby
Raw Normal View History

2021-03-19 17:31:38 +02:00
class ApplicationController < ActionController::Base
2021-03-20 20:02:37 +01:00
helper_method :current_user
helper_method :logged_in?
2021-03-21 17:02:04 +01:00
2021-03-20 20:02:37 +01:00
def current_user
User.find_by(id: session[:user_id])
end
2021-03-21 17:02:04 +01:00
2021-03-20 20:02:37 +01:00
def logged_in?
!current_user.nil?
end
2021-03-21 17:02:04 +01:00
def notices_from_errors(record)
messages = record.errors.messages.map do |attribute, messages|
messages.map { |message| "#{attribute} #{message}".capitalize }
end
messages.flatten
end
2021-03-19 17:31:38 +02:00
end