module Alchemy::ControllerActions
Private Instance Methods
alchemy_user_signed_in?()
click to toggle source
Returns true if a current_alchemy_user
is present
# File lib/alchemy/controller_actions.rb, line 45 def alchemy_user_signed_in? current_alchemy_user.present? end
current_alchemy_site()
click to toggle source
Returns the current site.
# File lib/alchemy/controller_actions.rb, line 51 def current_alchemy_site @current_alchemy_site ||= Site.find_for_host(request.host) end
current_alchemy_user()
click to toggle source
The current authorized user.
In order to have Alchemy’s authorization work, you have to provide a current_user
method in your app’s ApplicationController, that returns the current user. To change the method current_alchemy_user
will call, set Alchemy.current_user_method
to a different method name.
If you don’t have an App that can provide a current_user
object, you can install the ‘alchemy-devise` gem that provides everything you need.
# File lib/alchemy/controller_actions.rb, line 36 def current_alchemy_user current_user_method = Alchemy.current_user_method raise NoCurrentUserFoundError if !respond_to?(current_user_method, true) send current_user_method end
current_server()
click to toggle source
Returns a host string with the domain the app is running on.
# File lib/alchemy/controller_actions.rb, line 22 def current_server "#{request.protocol}#{request.host_with_port}" end
load_alchemy_language_from_id_or_code(id_or_code)
click to toggle source
# File lib/alchemy/controller_actions.rb, line 81 def load_alchemy_language_from_id_or_code(id_or_code) Language.find_by(id: id_or_code) || Language.find_by_code(id_or_code) end
load_alchemy_language_from_params()
click to toggle source
# File lib/alchemy/controller_actions.rb, line 74 def load_alchemy_language_from_params if params[:locale].present? Language.find_by_code(params[:locale]) || raise(ActionController::RoutingError, "Language not found") end end
set_alchemy_language(lang = nil)
click to toggle source
Sets the current language for Alchemy
.
# File lib/alchemy/controller_actions.rb, line 64 def set_alchemy_language(lang = nil) @language = if lang lang.is_a?(Language) ? lang : load_alchemy_language_from_id_or_code(lang) else load_alchemy_language_from_params || Language.default end store_current_alchemy_language(@language) end
set_current_alchemy_site()
click to toggle source
Sets the current site in a cvar so the Language model can be scoped against it.
# File lib/alchemy/controller_actions.rb, line 58 def set_current_alchemy_site Current.site = current_alchemy_site end
store_current_alchemy_language(language)
click to toggle source
Stores language in Current.language
# File lib/alchemy/controller_actions.rb, line 88 def store_current_alchemy_language(language) if language&.id Current.language = language end end