Skip to content

Instantly share code, notes, and snippets.

@yelinaung
Created June 12, 2013 09:08
Show Gist options
  • Save yelinaung/5763890 to your computer and use it in GitHub Desktop.
Save yelinaung/5763890 to your computer and use it in GitHub Desktop.
Application Controller
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :get_menu_ready
def after_sign_in_path_for(resource)
session[:return_to] = request.fullpath if request.get? and controller_name != "user_sessions" and controller_name != "sessions"
end
def after_sign_out_path_for(resource)
request.referrer
end
def get_menu_ready
#TODO: Store the menu in User's session
if(!@menu_config or request.params["menu_refresh"] == "1")
@menu_config = YAML.load(SysParam.where(:key => "main_menu")[0].value)
end
end
protected
def is_system_admin?
redirect_to "/", error: 'You dont have enough permissions to be here' unless current_backend_user.user_role.code == "co12345"
true
end
def is_company_admin?
redirect_to "/", error: 'You dont have enough permissions to be here' unless current_backend_user.user_role.code == "co56789" || current_backend_user.user_role.code == "co12345"
true
end
def is_retail_agent?
if current_backend_user.user_role.code === "co56789" || current_backend_user.user_role.code === "co65466" || current_backend_user.user_role.code === "co12345"
return true
else
redirect_to "/", error: 'You dont have enough permissions to be here'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment