Module: Mokio::Concerns::Controllers::Base
- Extended by:
- ActiveSupport::Concern
- Included in:
- BaseController
- Defined in:
- lib/mokio/concerns/controllers/base.rb
Overview
Concern for BaseController
Instance Method Summary collapse
-
#current_ability ⇒ Object
override current_ability to use Mokio’s one.
-
#flash_to_headers ⇒ Object
Sending flash messages in X-Flash-Messages header.
- #prepare_locale ⇒ Object
-
#redirect_back(format, url, message) ⇒ Object
Redirects back if back if available otherwise redirects to specified url, flash message is displayed.
- #set_breadcrumbs_prefix ⇒ Object
Instance Method Details
#current_ability ⇒ Object
override current_ability to use Mokio’s one
61 62 63 |
# File 'lib/mokio/concerns/controllers/base.rb', line 61 def current_ability @current_ability ||= Mokio::Ability.new(current_user) end |
#flash_to_headers ⇒ Object
Sending flash messages in X-Flash-Messages header. Decoding to UTF-8 with ajax success placed in main.js. after_action in BaseController
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mokio/concerns/controllers/base.rb', line 27 def flash_to_headers if request.xhr? = {} [:notice] = CGI::escape(flash[:notice].to_str) if flash[:notice] [:error] = CGI::escape(flash[:error].to_str) if flash[:error] [:info] = CGI::escape(flash[:info].to_str) if flash[:info] response.headers['X-Flash-Messages'] = .to_json flash.discard end end |
#prepare_locale ⇒ Object
53 54 55 56 |
# File 'lib/mokio/concerns/controllers/base.rb', line 53 def prepare_locale I18n.locale = session[:locale_cms] || Mokio.cms_locale session[:locale_cms] = I18n.locale end |
#redirect_back(format, url, message) ⇒ Object
Redirects back if back if available otherwise redirects to specified url, flash message is displayed
43 44 45 46 |
# File 'lib/mokio/concerns/controllers/base.rb', line 43 def redirect_back(format, url, ) format.html { redirect_to url, notice: } format.json { head :no_content } end |
#set_breadcrumbs_prefix ⇒ Object
48 49 50 51 |
# File 'lib/mokio/concerns/controllers/base.rb', line 48 def @breadcrumbs_prefix = "" @breadcrumbs_prefix_link = "" end |