Sha256: b7f1ec7d51c6602bb367aaa5d1d8401fd729b2a9479996b41f3531e3a47689ff
Contents?: true
Size: 1.99 KB
Versions: 2
Compression:
Stored size: 1.99 KB
Contents
require 'rails_admin/abstract_model' module RailsAdmin class ModelNotFound < ::StandardError end class ObjectNotFound < ::StandardError end class ActionNotAllowed < ::StandardError end class ApplicationController < Config.parent_controller.constantize before_action :_authenticate! before_action :_authorize! before_action :_audit! helper_method :_current_user, :_get_plugin_name attr_reader :object, :model_config, :abstract_model, :authorization_adapter def get_model @model_name = to_model_name(params[:model_name]) raise(RailsAdmin::ModelNotFound) unless (@abstract_model = RailsAdmin::AbstractModel.new(@model_name)) raise(RailsAdmin::ModelNotFound) if (@model_config = @abstract_model.config).excluded? @properties = @abstract_model.properties end def get_object raise(RailsAdmin::ObjectNotFound) unless (@object = @abstract_model.get(params[:id])) end def to_model_name(param) param.split('~').collect(&:camelize).join('::') end def _current_user instance_eval(&RailsAdmin::Config.current_user_method) end private def _get_plugin_name @plugin_name_array ||= [RailsAdmin.config.main_app_name.is_a?(Proc) ? instance_eval(&RailsAdmin.config.main_app_name) : RailsAdmin.config.main_app_name].flatten end def _authenticate! instance_eval(&RailsAdmin::Config.authenticate_with) end def _authorize! instance_eval(&RailsAdmin::Config.authorize_with) end def _audit! instance_eval(&RailsAdmin::Config.audit_with) end def rails_admin_controller? true end rescue_from RailsAdmin::ObjectNotFound do flash[:error] = I18n.t('admin.flash.object_not_found', model: @model_name, id: params[:id]) params[:action] = 'index' index end rescue_from RailsAdmin::ModelNotFound do flash[:error] = I18n.t('admin.flash.model_not_found', model: @model_name) params[:action] = 'dashboard' dashboard end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rails_admin-1.1.0 | app/controllers/rails_admin/application_controller.rb |
rails_admin-1.0.0 | app/controllers/rails_admin/application_controller.rb |