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/actions/new.rb,
lib/rails_admin/config/fields/base.rb,
lib/rails_admin/config/inspectable.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/citext.rb,
lib/rails_admin/config/fields/types/froala.rb,
lib/rails_admin/config/fields/types/hidden.rb,
lib/rails_admin/config/fields/types/shrine.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/fields/types/numeric.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/simple_mde.rb,
lib/rails_admin/config/fields/types/action_text.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/string_like.rb,
lib/rails_admin/config/fields/types/active_storage.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/multiple_carrierwave.rb,
lib/rails_admin/config/fields/types/multiple_file_upload.rb,
lib/rails_admin/config/fields/types/belongs_to_association.rb,
lib/rails_admin/config/fields/types/multiple_active_storage.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, Inspectable, Proxyable, Sections Classes: 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
- .asset_source ⇒ Object
-
.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_associated_collection_limit ⇒ Object
Default association limit.
-
.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.
-
.forgery_protection_settings ⇒ Object
set settings for ‘protect_from_forgery` method By default, it raises exception upon invalid CSRF tokens.
-
.included_models ⇒ Object
Configuration option to specify a allowlist 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.
-
.show_gravatar ⇒ Object
show Gravatar in Navigation bar.
Class Method Summary collapse
-
.actions(&block) ⇒ Object
Setup actions to be used.
-
.apply(&block) ⇒ Object
Evaluate the given block either immediately or lazily, based on initialization status.
-
.audit_with(*args, &block) ⇒ Object
Setup auditing/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.
-
.initialize! ⇒ Object
Finish initialization by executing deferred configuration blocks.
-
.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.
-
.reload! ⇒ Object
Perform reset, then load RailsAdmin initializer again.
-
.reset ⇒ Object
Reset all configurations to defaults.
-
.reset_model(model) ⇒ Object
Reset a provided model’s configuration.
- .sidescroll=(_) ⇒ Object
- .total_columns_width=(_) ⇒ Object
-
.visible_models(bindings) ⇒ Object
Get all models that are configured as visible sorted by their weight and label.
Class Attribute Details
.asset_source ⇒ Object
260 261 262 263 264 265 266 267 268 269 |
# File 'lib/rails_admin/config.rb', line 260 def asset_source @asset_source ||= begin warn " [Warning] After upgrading RailsAdmin to 3.x you haven't set asset_source yet, using :sprockets as the default.\n To suppress this message, run 'rails rails_admin:install' to setup the asset delivery method suitable to you.\n MSG\n :sprockets\n end\nend\n".gsub(/^ +/, '').freeze |
.browser_validations ⇒ Object
Tell browsers whether to use the native HTML5 validations (novalidate form option).
61 62 63 |
# File 'lib/rails_admin/config.rb', line 61 def browser_validations @browser_validations end |
.compact_show_view ⇒ Object
hide blank fields in show view if true
58 59 60 |
# File 'lib/rails_admin/config.rb', line 58 def compact_show_view @compact_show_view end |
.default_associated_collection_limit ⇒ Object
Default association limit
49 50 51 |
# File 'lib/rails_admin/config.rb', line 49 def default_associated_collection_limit @default_associated_collection_limit end |
.default_hidden_fields ⇒ Object
Fields to be hidden in show, create and update views
42 43 44 |
# File 'lib/rails_admin/config.rb', line 42 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
46 47 48 |
# File 'lib/rails_admin/config.rb', line 46 def default_items_per_page @default_items_per_page end |
.default_search_operator ⇒ Object
Returns the value of attribute default_search_operator.
51 52 53 |
# File 'lib/rails_admin/config.rb', line 51 def default_search_operator @default_search_operator end |
.excluded_models ⇒ Object
Configuration option to specify which models you want to exclude.
32 33 34 |
# File 'lib/rails_admin/config.rb', line 32 def excluded_models @excluded_models end |
.forgery_protection_settings ⇒ Object
set settings for ‘protect_from_forgery` method By default, it raises exception upon invalid CSRF tokens
68 69 70 |
# File 'lib/rails_admin/config.rb', line 68 def forgery_protection_settings @forgery_protection_settings end |
.included_models ⇒ Object
Configuration option to specify a allowlist of models you want to RailsAdmin to work with. The excluded_models list applies against the allowlist 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).
39 40 41 |
# File 'lib/rails_admin/config.rb', line 39 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]
55 56 57 |
# File 'lib/rails_admin/config.rb', line 55 def label_methods @label_methods end |
.main_app_name ⇒ Object
Application title, can be an array of two elements
29 30 31 |
# File 'lib/rails_admin/config.rb', line 29 def main_app_name @main_app_name end |
.navigation_static_label ⇒ Object
Returns the value of attribute navigation_static_label.
81 82 83 |
# File 'lib/rails_admin/config.rb', line 81 def end |
.navigation_static_links ⇒ Object
accepts a hash of static links to be shown below the main navigation
80 81 82 |
# File 'lib/rails_admin/config.rb', line 80 def end |
.parent_controller ⇒ Object
set parent controller
64 65 66 |
# File 'lib/rails_admin/config.rb', line 64 def parent_controller @parent_controller end |
.registry ⇒ Object (readonly)
Stores model configuration objects in a hash identified by model’s class name.
74 75 76 |
# File 'lib/rails_admin/config.rb', line 74 def registry @registry end |
.show_gravatar ⇒ Object
show Gravatar in Navigation bar
77 78 79 |
# File 'lib/rails_admin/config.rb', line 77 def show_gravatar @show_gravatar end |
Class Method Details
.actions(&block) ⇒ Object
Setup actions to be used.
301 302 303 304 305 306 |
# File 'lib/rails_admin/config.rb', line 301 def actions(&block) return unless block RailsAdmin::Config::Actions.reset RailsAdmin::Config::Actions.instance_eval(&block) end |
.apply(&block) ⇒ Object
Evaluate the given block either immediately or lazily, based on initialization status.
94 95 96 97 98 99 100 |
# File 'lib/rails_admin/config.rb', line 94 def apply(&block) if @initialized yield(self) else @deferred_blocks << block end end |
.audit_with(*args, &block) ⇒ Object
Setup auditing/versioning provider that observe objects lifecycle
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/rails_admin/config.rb', line 131 def audit_with(*args, &block) extension = args.shift if extension klass = RailsAdmin::AUDITING_ADAPTERS[extension] klass.setup if klass.respond_to? :setup @audit = proc do @auditing_adapter = klass.new(*([self] + args).compact) end elsif block @audit = 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!
125 126 127 128 |
# File 'lib/rails_admin/config.rb', line 125 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 CanCanCan, pass it like this.
See the wiki for more on authorization.
168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/rails_admin/config.rb', line 168 def (*args, &block) extension = args.shift if extension klass = RailsAdmin::AUTHORIZATION_ADAPTERS[extension] klass.setup if klass.respond_to? :setup = proc do = klass.new(*([self] + args).compact) end elsif block = block end || DEFAULT_AUTHORIZE end |
.configure_with(extension) {|configuration| ... } ⇒ Object
Setup configuration using an extension-provided ConfigurationAdapter
194 195 196 197 |
# File 'lib/rails_admin/config.rb', line 194 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.
212 213 214 215 |
# File 'lib/rails_admin/config.rb', line 212 def current_user_method(&block) @current_user = block if block @current_user || DEFAULT_CURRENT_USER end |
.initialize! ⇒ Object
Finish initialization by executing deferred configuration blocks
87 88 89 90 91 |
# File 'lib/rails_admin/config.rb', line 87 def initialize! @deferred_blocks.each { |block| block.call(self) } @deferred_blocks.clear @initialized = true 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
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/rails_admin/config.rb', line 242 def model(entity, &block) key = case entity when RailsAdmin::AbstractModel entity.model.try(:name).try :to_sym when Class entity.name.to_sym when String, Symbol entity.to_sym else entity.class.name.to_sym end @registry[key] ||= RailsAdmin::Config::Model.new(entity) @registry[key].instance_eval(&block) if block && @registry[key].abstract_model @registry[key] end |
.models ⇒ Object
Returns all model configurations
311 312 313 |
# File 'lib/rails_admin/config.rb', line 311 def models RailsAdmin::AbstractModel.all.collect { |m| model(m) } end |
.models_pool ⇒ Object
pool of all found model names from the whole application
226 227 228 |
# File 'lib/rails_admin/config.rb', line 226 def models_pool (viable_models - excluded_models.collect(&:to_s)).uniq.sort end |
.reload! ⇒ Object
Perform reset, then load RailsAdmin initializer again
356 357 358 359 360 361 |
# File 'lib/rails_admin/config.rb', line 356 def reload! @initialized = false reset load RailsAdmin::Engine.config.initializer_path initialize! end |
.reset ⇒ Object
Reset all configurations to defaults.
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/rails_admin/config.rb', line 318 def reset @compact_show_view = true @browser_validations = true @authenticate = nil = nil @audit = nil @current_user = nil @default_hidden_fields = {} @default_hidden_fields[:base] = [:_type] @default_hidden_fields[:edit] = i[id _id created_at created_on deleted_at updated_at updated_on deleted_on] @default_hidden_fields[:show] = i[id _id created_at created_on deleted_at updated_at updated_on deleted_on] @default_items_per_page = 20 @default_associated_collection_limit = 100 @default_search_operator = 'default' @excluded_models = [] @included_models = [] @label_methods = i[name title] @main_app_name = proc { [Rails.application.engine_name.titleize.chomp(' Application'), 'Admin'] } @registry = {} @show_gravatar = true = {} = nil @asset_source = nil @parent_controller = '::ActionController::Base' @forgery_protection_settings = {with: :exception} RailsAdmin::Config::Actions.reset RailsAdmin::AbstractModel.reset end |
.reset_model(model) ⇒ Object
Reset a provided model’s configuration.
350 351 352 353 |
# File 'lib/rails_admin/config.rb', line 350 def reset_model(model) key = model.is_a?(Class) ? model.name.to_sym : model.to_sym @registry.delete(key) end |
.sidescroll=(_) ⇒ Object
296 297 298 |
# File 'lib/rails_admin/config.rb', line 296 def sidescroll=(_) ActiveSupport::Deprecation.warn('The sidescroll configuration option was removed, it is always enabled now.') end |
.total_columns_width=(_) ⇒ Object
292 293 294 |
# File 'lib/rails_admin/config.rb', line 292 def total_columns_width=(_) ActiveSupport::Deprecation.warn('The total_columns_width configuration option is deprecated and has no effect.') end |
.visible_models(bindings) ⇒ Object
Get all models that are configured as visible sorted by their weight and label.
366 367 368 369 370 371 372 373 374 |
# File 'lib/rails_admin/config.rb', line 366 def visible_models(bindings) visible_models_with_bindings(bindings).sort do |a, b| if (weight_order = a.weight <=> b.weight) == 0 a.label.casecmp(b.label) else weight_order end end end |