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

Instance Method Details

#current_abilityObject

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_headersObject

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?
    flash_messages = {}

    flash_messages[:notice] = CGI::escape(flash[:notice].to_str) if flash[:notice]
    flash_messages[:error]  = CGI::escape(flash[:error].to_str) if flash[:error]
    flash_messages[:info]   = CGI::escape(flash[:info].to_str) if flash[:info]

    response.headers['X-Flash-Messages'] = flash_messages.to_json
    flash.discard
  end
end

#prepare_localeObject



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, message)
  format.html { redirect_to url, notice: message }
  format.json { head :no_content }
end

#set_breadcrumbs_prefixObject



48
49
50
51
# File 'lib/mokio/concerns/controllers/base.rb', line 48

def set_breadcrumbs_prefix
  @breadcrumbs_prefix = ""
  @breadcrumbs_prefix_link = ""
end