Module: RailsAdmin::Config
- Defined in:
- lib/rails_admin/config.rb,
lib/rails_admin/config/model.rb,
lib/rails_admin/config/fields.rb,
lib/rails_admin/config/actions.rb,
lib/rails_admin/config/hideable.rb,
lib/rails_admin/config/sections.rb,
lib/rails_admin/config/groupable.rb,
lib/rails_admin/config/proxyable.rb,
lib/rails_admin/config/has_fields.rb,
lib/rails_admin/config/has_groups.rb,
lib/rails_admin/config/lazy_model.rb,
lib/rails_admin/config/actions/new.rb,
lib/rails_admin/config/fields/base.rb,
lib/rails_admin/config/actions/base.rb,
lib/rails_admin/config/actions/edit.rb,
lib/rails_admin/config/actions/show.rb,
lib/rails_admin/config/configurable.rb,
lib/rails_admin/config/fields/group.rb,
lib/rails_admin/config/fields/types.rb,
lib/rails_admin/config/actions/index.rb,
lib/rails_admin/config/sections/base.rb,
lib/rails_admin/config/sections/edit.rb,
lib/rails_admin/config/sections/list.rb,
lib/rails_admin/config/sections/show.rb,
lib/rails_admin/config/actions/delete.rb,
lib/rails_admin/config/actions/export.rb,
lib/rails_admin/config/sections/modal.rb,
lib/rails_admin/config/has_description.rb,
lib/rails_admin/config/proxyable/proxy.rb,
lib/rails_admin/config/sections/create.rb,
lib/rails_admin/config/sections/export.rb,
lib/rails_admin/config/sections/nested.rb,
lib/rails_admin/config/sections/update.rb,
lib/rails_admin/config/actions/dashboard.rb,
lib/rails_admin/config/fields/types/date.rb,
lib/rails_admin/config/fields/types/enum.rb,
lib/rails_admin/config/fields/types/inet.rb,
lib/rails_admin/config/fields/types/json.rb,
lib/rails_admin/config/fields/types/text.rb,
lib/rails_admin/config/fields/types/time.rb,
lib/rails_admin/config/fields/types/uuid.rb,
lib/rails_admin/config/fields/association.rb,
lib/rails_admin/config/fields/types/color.rb,
lib/rails_admin/config/fields/types/float.rb,
lib/rails_admin/config/actions/bulk_delete.rb,
lib/rails_admin/config/actions/show_in_app.rb,
lib/rails_admin/config/fields/types/froala.rb,
lib/rails_admin/config/fields/types/hidden.rb,
lib/rails_admin/config/fields/types/refile.rb,
lib/rails_admin/config/fields/types/string.rb,
lib/rails_admin/config/actions/history_show.rb,
lib/rails_admin/config/fields/types/boolean.rb,
lib/rails_admin/config/fields/types/decimal.rb,
lib/rails_admin/config/fields/types/integer.rb,
lib/rails_admin/config/actions/history_index.rb,
lib/rails_admin/config/fields/types/datetime.rb,
lib/rails_admin/config/fields/types/password.rb,
lib/rails_admin/config/fields/types/ck_editor.rb,
lib/rails_admin/config/fields/types/dragonfly.rb,
lib/rails_admin/config/fields/types/paperclip.rb,
lib/rails_admin/config/fields/types/timestamp.rb,
lib/rails_admin/config/fields/types/wysihtml5.rb,
lib/rails_admin/config/fields/types/serialized.rb,
lib/rails_admin/config/fields/types/carrierwave.rb,
lib/rails_admin/config/fields/types/code_mirror.rb,
lib/rails_admin/config/fields/types/file_upload.rb,
lib/rails_admin/config/fields/types/bson_object_id.rb,
lib/rails_admin/config/fields/types/active_record_enum.rb,
lib/rails_admin/config/fields/types/has_one_association.rb,
lib/rails_admin/config/fields/types/has_many_association.rb,
lib/rails_admin/config/fields/types/belongs_to_association.rb,
lib/rails_admin/config/fields/types/polymorphic_association.rb,
lib/rails_admin/config/fields/types/has_and_belongs_to_many_association.rb
Defined Under Namespace
Modules: Actions, Configurable, Fields, Groupable, HasDescription, HasFields, HasGroups, Hideable, Proxyable, Sections Classes: LazyModel, Model
Constant Summary collapse
- DEFAULT_AUTHENTICATION =
RailsAdmin is setup to try and authenticate with warden If warden is found, then it will try to authenticate
This is valid for custom warden setups, and also devise If you’re using the admin setup for devise, you should set RailsAdmin to use the admin
proc {}
- DEFAULT_AUTHORIZE =
proc {}
- DEFAULT_AUDIT =
proc {}
- DEFAULT_CURRENT_USER =
proc {}
Class Attribute Summary collapse
-
.browser_validations ⇒ Object
Tell browsers whether to use the native HTML5 validations (novalidate form option).
-
.compact_show_view ⇒ Object
hide blank fields in show view if true.
-
.default_hidden_fields ⇒ Object
Fields to be hidden in show, create and update views.
-
.default_items_per_page ⇒ Object
Default items per page value used if a model level option has not been configured.
-
.default_search_operator ⇒ Object
Returns the value of attribute default_search_operator.
-
.excluded_models ⇒ Object
Configuration option to specify which models you want to exclude.
-
.included_models ⇒ Object
Configuration option to specify a whitelist of models you want to RailsAdmin to work with.
-
.label_methods ⇒ Object
Configuration option to specify which method names will be searched for to be used as a label for object records.
-
.main_app_name ⇒ Object
Application title, can be an array of two elements.
-
.navigation_static_label ⇒ Object
Returns the value of attribute navigation_static_label.
-
.navigation_static_links ⇒ Object
accepts a hash of static links to be shown below the main navigation.
-
.parent_controller ⇒ Object
set parent controller.
-
.registry ⇒ Object
readonly
Stores model configuration objects in a hash identified by model’s class name.
-
.total_columns_width ⇒ Object
Set the max width of columns in list view before a new set is created.
-
.yell_for_non_accessible_fields ⇒ Object
yell about fields that are not marked as accessible.
Class Method Summary collapse
-
.actions(&block) ⇒ Object
Returns action configuration object.
-
.audit_with(*args, &block) ⇒ Object
Setup auditing/history/versioning provider that observe objects lifecycle.
-
.authenticate_with(&blk) ⇒ Object
Setup authentication to be run as a before filter This is run inside the controller instance so you can setup any authentication you need to.
-
.authorize_with(*args, &block) ⇒ Object
Setup authorization to be run as a before filter This is run inside the controller instance so you can setup any authorization you need to.
-
.configure_with(extension) {|configuration| ... } ⇒ Object
Setup configuration using an extension-provided ConfigurationAdapter.
-
.current_user_method(&block) ⇒ Object
Setup a different method to determine the current user or admin logged in.
-
.model(entity, &block) ⇒ Object
Loads a model configuration instance from the registry or registers a new one if one is yet to be added.
-
.models ⇒ Object
Returns all model configurations.
-
.models_pool ⇒ Object
pool of all found model names from the whole application.
-
.reset ⇒ Object
Reset all configurations to defaults.
-
.reset_model(model) ⇒ Object
Reset a provided model’s configuration.
-
.visible_models(bindings) ⇒ Object
Get all models that are configured as visible sorted by their weight and label.
Class Attribute Details
.browser_validations ⇒ Object
Tell browsers whether to use the native HTML5 validations (novalidate form option).
54 55 56 |
# File 'lib/rails_admin/config.rb', line 54 def browser_validations @browser_validations end |
.compact_show_view ⇒ Object
hide blank fields in show view if true
51 52 53 |
# File 'lib/rails_admin/config.rb', line 51 def compact_show_view @compact_show_view end |
.default_hidden_fields ⇒ Object
Fields to be hidden in show, create and update views
38 39 40 |
# File 'lib/rails_admin/config.rb', line 38 def default_hidden_fields @default_hidden_fields end |
.default_items_per_page ⇒ Object
Default items per page value used if a model level option has not been configured
42 43 44 |
# File 'lib/rails_admin/config.rb', line 42 def default_items_per_page @default_items_per_page end |
.default_search_operator ⇒ Object
Returns the value of attribute default_search_operator.
44 45 46 |
# File 'lib/rails_admin/config.rb', line 44 def default_search_operator @default_search_operator end |
.excluded_models ⇒ Object
Configuration option to specify which models you want to exclude.
28 29 30 |
# File 'lib/rails_admin/config.rb', line 28 def excluded_models @excluded_models end |
.included_models ⇒ Object
Configuration option to specify a whitelist of models you want to RailsAdmin to work with. The excluded_models list applies against the whitelist as well and further reduces the models RailsAdmin will use. If included_models is left empty ([]), then RailsAdmin will automatically use all the models in your application (less any excluded_models you may have specified).
35 36 37 |
# File 'lib/rails_admin/config.rb', line 35 def included_models @included_models end |
.label_methods ⇒ Object
Configuration option to specify which method names will be searched for to be used as a label for object records. This defaults to [:name, :title]
48 49 50 |
# File 'lib/rails_admin/config.rb', line 48 def label_methods @label_methods end |
.main_app_name ⇒ Object
Application title, can be an array of two elements
25 26 27 |
# File 'lib/rails_admin/config.rb', line 25 def main_app_name @main_app_name end |
.navigation_static_label ⇒ Object
Returns the value of attribute navigation_static_label.
70 71 72 |
# File 'lib/rails_admin/config.rb', line 70 def @navigation_static_label end |
.navigation_static_links ⇒ Object
accepts a hash of static links to be shown below the main navigation
69 70 71 |
# File 'lib/rails_admin/config.rb', line 69 def @navigation_static_links end |
.parent_controller ⇒ Object
set parent controller
60 61 62 |
# File 'lib/rails_admin/config.rb', line 60 def parent_controller @parent_controller end |
.registry ⇒ Object (readonly)
Stores model configuration objects in a hash identified by model’s class name.
66 67 68 |
# File 'lib/rails_admin/config.rb', line 66 def registry @registry end |
.total_columns_width ⇒ Object
Set the max width of columns in list view before a new set is created
57 58 59 |
# File 'lib/rails_admin/config.rb', line 57 def total_columns_width @total_columns_width end |
.yell_for_non_accessible_fields ⇒ Object
yell about fields that are not marked as accessible
73 74 75 |
# File 'lib/rails_admin/config.rb', line 73 def yell_for_non_accessible_fields @yell_for_non_accessible_fields end |
Class Method Details
.actions(&block) ⇒ Object
Returns action configuration object
244 245 246 |
# File 'lib/rails_admin/config.rb', line 244 def actions(&block) RailsAdmin::Config::Actions.instance_eval(&block) if block end |
.audit_with(*args, &block) ⇒ Object
Setup auditing/history/versioning provider that observe objects lifecycle
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/rails_admin/config.rb', line 104 def audit_with(*args, &block) extension = args.shift if extension @audit = proc do @auditing_adapter = RailsAdmin::AUDITING_ADAPTERS[extension].new(*([self] + args).compact) end else @audit = block if block end @audit || DEFAULT_AUDIT end |
.authenticate_with(&blk) ⇒ Object
Setup authentication to be run as a before filter This is run inside the controller instance so you can setup any authentication you need to
By default, the authentication will run via warden if available and will run the default.
If you use devise, this will authenticate the same as authenticate_user!
98 99 100 101 |
# File 'lib/rails_admin/config.rb', line 98 def authenticate_with(&blk) @authenticate = blk if blk @authenticate || DEFAULT_AUTHENTICATION end |
.authorize_with(*args, &block) ⇒ Object
Setup authorization to be run as a before filter This is run inside the controller instance so you can setup any authorization you need to.
By default, there is no authorization.
To use an authorization adapter, pass the name of the adapter. For example, to use with CanCan, pass it like this.
See the wiki for more on authorization.
139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/rails_admin/config.rb', line 139 def (*args, &block) extension = args.shift if extension @authorize = proc do @authorization_adapter = RailsAdmin::AUTHORIZATION_ADAPTERS[extension].new(*([self] + args).compact) end else @authorize = block if block end @authorize || DEFAULT_AUTHORIZE end |
.configure_with(extension) {|configuration| ... } ⇒ Object
Setup configuration using an extension-provided ConfigurationAdapter
163 164 165 166 |
# File 'lib/rails_admin/config.rb', line 163 def configure_with(extension) configuration = RailsAdmin::CONFIGURATION_ADAPTERS[extension].new yield(configuration) if block_given? end |
.current_user_method(&block) ⇒ Object
Setup a different method to determine the current user or admin logged in. This is run inside the controller instance and made available as a helper.
By default, _request.env.user_ or current_user will be used.
181 182 183 184 |
# File 'lib/rails_admin/config.rb', line 181 def current_user_method(&block) @current_user = block if block @current_user || DEFAULT_CURRENT_USER end |
.model(entity, &block) ⇒ Object
Loads a model configuration instance from the registry or registers a new one if one is yet to be added.
First argument can be an instance of requested model, its class object, its class name as a string or symbol or a RailsAdmin::AbstractModel instance.
If a block is given it is evaluated in the context of configuration instance.
Returns given model’s configuration
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/rails_admin/config.rb', line 213 def model(entity, &block) key = begin if entity.is_a?(RailsAdmin::AbstractModel) entity.model.try(:name).try :to_sym elsif entity.is_a?(Class) entity.name.to_sym elsif entity.is_a?(String) || entity.is_a?(Symbol) entity.to_sym else entity.class.name.to_sym end end if block @registry[key] = RailsAdmin::Config::LazyModel.new(entity, &block) else @registry[key] ||= RailsAdmin::Config::LazyModel.new(entity) end end |
.models ⇒ Object
Returns all model configurations
251 252 253 |
# File 'lib/rails_admin/config.rb', line 251 def models RailsAdmin::AbstractModel.all.collect { |m| model(m) } end |
.models_pool ⇒ Object
pool of all found model names from the whole application
195 196 197 198 199 |
# File 'lib/rails_admin/config.rb', line 195 def models_pool excluded = (excluded_models.collect(&:to_s) + ['RailsAdmin::History']) (viable_models - excluded).uniq.sort end |
.reset ⇒ Object
Reset all configurations to defaults.
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/rails_admin/config.rb', line 258 def reset @compact_show_view = true @browser_validations = true @yell_for_non_accessible_fields = true @authenticate = nil @authorize = nil @audit = nil @current_user = nil @default_hidden_fields = {} @default_hidden_fields[:base] = [:_type] @default_hidden_fields[:edit] = [:id, :_id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on] @default_hidden_fields[:show] = [:id, :_id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on] @default_items_per_page = 20 @default_search_operator = 'default' @excluded_models = [] @included_models = [] @total_columns_width = 697 @label_methods = [:name, :title] @main_app_name = proc { [Rails.application.engine_name.titleize.chomp(' Application'), 'Admin'] } @registry = {} @navigation_static_links = {} @navigation_static_label = nil @parent_controller = '::ApplicationController' RailsAdmin::Config::Actions.reset end |
.reset_model(model) ⇒ Object
Reset a provided model’s configuration.
287 288 289 290 |
# File 'lib/rails_admin/config.rb', line 287 def reset_model(model) key = model.is_a?(Class) ? model.name.to_sym : model.to_sym @registry.delete(key) end |
.visible_models(bindings) ⇒ Object
Get all models that are configured as visible sorted by their weight and label.
296 297 298 299 300 301 302 303 304 |
# File 'lib/rails_admin/config.rb', line 296 def visible_models(bindings) visible_models_with_bindings(bindings).sort do |a, b| if (weight_order = a.weight <=> b.weight) == 0 a.label.downcase <=> b.label.downcase else weight_order end end end |