Module: RailsAdmin::Config
- Defined in:
- lib/rails_admin/config.rb,
lib/rails_admin/config/base.rb,
lib/rails_admin/config/model.rb,
lib/rails_admin/config/proxy.rb,
lib/rails_admin/config/fields.rb,
lib/rails_admin/config/hideable.rb,
lib/rails_admin/config/sections.rb,
lib/rails_admin/config/has_fields.rb,
lib/rails_admin/config/has_groups.rb,
lib/rails_admin/config/fields/base.rb,
lib/rails_admin/config/fields/group.rb,
lib/rails_admin/config/fields/types.rb,
lib/rails_admin/config/sections/list.rb,
lib/rails_admin/config/sections/show.rb,
lib/rails_admin/config/sections/create.rb,
lib/rails_admin/config/sections/export.rb,
lib/rails_admin/config/sections/update.rb,
lib/rails_admin/config/fields/groupable.rb,
lib/rails_admin/config/fields/types/date.rb,
lib/rails_admin/config/fields/types/enum.rb,
lib/rails_admin/config/fields/types/text.rb,
lib/rails_admin/config/fields/types/time.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/fields/types/string.rb,
lib/rails_admin/config/sections/navigation.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/datetime.rb,
lib/rails_admin/config/fields/types/password.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/carrierwave.rb,
lib/rails_admin/config/fields/types/file_upload.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: Fields, HasFields, HasGroups, Hideable, Sections Classes: Base, Model, Proxy
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
By default, this will raise in any of the following environments
* production * beta * uat * staging
Proc.new do request.env['warden'].try(:authenticate!) end
- DEFAULT_ATTR_ACCESSIBLE_ROLE =
Proc.new { :default }
- DEFAULT_AUTHORIZE =
Proc.new {}
- DEFAULT_CURRENT_USER =
Proc.new do request.env["warden"].try(:user) || respond_to?(:current_user) && current_user end
Class Attribute Summary collapse
-
.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.
-
.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.
Class Method Summary collapse
- .attr_accessible_role(&blk) ⇒ Object
-
.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.
-
.list ⇒ Object
Shortcut to access the list section’s class configuration within a config DSL block.
-
.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(&block) ⇒ Object
Returns all model configurations.
-
.navigation ⇒ Object
Shortcut to access the navigation section’s class configuration within a config DSL block.
- .reload_between_requests=(thingy) ⇒ Object
-
.reset ⇒ Object
Reset all configurations to defaults.
-
.reset_model(model) ⇒ Object
Reset a provided model’s configuration.
-
.visible_models ⇒ Object
Get all models that are configured as visible sorted by their weight and label.
Class Attribute Details
.compact_show_view ⇒ Object
hide blank fields in show view if true
63 64 65 |
# File 'lib/rails_admin/config.rb', line 63 def compact_show_view @compact_show_view end |
.default_hidden_fields ⇒ Object
Fields to be hidden in show, create and update views
50 51 52 |
# File 'lib/rails_admin/config.rb', line 50 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
54 55 56 |
# File 'lib/rails_admin/config.rb', line 54 def default_items_per_page @default_items_per_page end |
.default_search_operator ⇒ Object
Returns the value of attribute default_search_operator.
56 57 58 |
# File 'lib/rails_admin/config.rb', line 56 def default_search_operator @default_search_operator end |
.excluded_models ⇒ Object
Configuration option to specify which models you want to exclude.
40 41 42 |
# File 'lib/rails_admin/config.rb', line 40 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).
47 48 49 |
# File 'lib/rails_admin/config.rb', line 47 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]
60 61 62 |
# File 'lib/rails_admin/config.rb', line 60 def label_methods @label_methods end |
.main_app_name ⇒ Object
Application title, can be an array of two elements
37 38 39 |
# File 'lib/rails_admin/config.rb', line 37 def main_app_name @main_app_name end |
.registry ⇒ Object (readonly)
Stores model configuration objects in a hash identified by model’s class name.
72 73 74 |
# File 'lib/rails_admin/config.rb', line 72 def registry @registry end |
.total_columns_width ⇒ Object
Set the max width of columns in list view before a new set is created
66 67 68 |
# File 'lib/rails_admin/config.rb', line 66 def total_columns_width @total_columns_width end |
Class Method Details
.attr_accessible_role(&blk) ⇒ Object
103 104 105 106 |
# File 'lib/rails_admin/config.rb', line 103 def attr_accessible_role(&blk) @attr_accessible_role = blk if blk @attr_accessible_role || DEFAULT_ATTR_ACCESSIBLE_ROLE 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!
97 98 99 100 |
# File 'lib/rails_admin/config.rb', line 97 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.
131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/rails_admin/config.rb', line 131 def (*args, &block) extension = args.shift if(extension) @authorize = Proc.new { @authorization_adapter = RailsAdmin::AUTHORIZATION_ADAPTERS[extension].new(*([self] + args).compact) } else @authorize = block if block end @authorize || DEFAULT_AUTHORIZE end |
.configure_with(extension) {|configuration| ... } ⇒ Object
Setup configuration using an extension-provided ConfigurationAdapter
155 156 157 158 |
# File 'lib/rails_admin/config.rb', line 155 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.
173 174 175 176 |
# File 'lib/rails_admin/config.rb', line 173 def current_user_method(&block) @current_user = block if block @current_user || DEFAULT_CURRENT_USER end |
.list ⇒ Object
Shortcut to access the list section’s class configuration within a config DSL block
194 195 196 197 |
# File 'lib/rails_admin/config.rb', line 194 def list ActiveSupport::Deprecation.warn("RailsAdmin::Config.list is deprecated", caller) RailsAdmin::Config::Sections::List 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
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/rails_admin/config.rb', line 211 def model(entity, &block) key = begin if entity.kind_of?(RailsAdmin::AbstractModel) entity.model.name.to_sym elsif entity.kind_of?(Class) entity.name.to_sym elsif entity.kind_of?(String) || entity.kind_of?(Symbol) entity.to_sym else entity.class.name.to_sym end end config = @registry[key] ||= RailsAdmin::Config::Model.new(entity) config.instance_eval(&block) if block config end |
.models(&block) ⇒ Object
Returns all model configurations
If a block is given it is evaluated in the context of configuration instances.
234 235 236 |
# File 'lib/rails_admin/config.rb', line 234 def models(&block) RailsAdmin::AbstractModel.all.map{|m| model(m, &block)} end |
.navigation ⇒ Object
Shortcut to access the navigation section’s class configuration within a config DSL block
242 243 244 245 |
# File 'lib/rails_admin/config.rb', line 242 def ActiveSupport::Deprecation.warn("RailsAdmin::Config.navigation is deprecated", caller) RailsAdmin::Config::Sections::Navigation end |
.reload_between_requests=(thingy) ⇒ Object
186 187 188 |
# File 'lib/rails_admin/config.rb', line 186 def reload_between_requests=(thingy) ActiveSupport::Deprecation.warn("'#{self.name}.reload_between_requests=' is not in use any longer, please remove it from initialization files", caller) end |
.reset ⇒ Object
Reset all configurations to defaults.
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/rails_admin/config.rb', line 250 def reset @compact_show_view = true @authenticate = nil @authorize = nil @current_user = nil @default_hidden_fields = [: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.new { [Rails.application.engine_name.titleize.chomp(' Application'), 'Admin'] } @registry = {} end |
.reset_model(model) ⇒ Object
Reset a provided model’s configuration.
269 270 271 272 |
# File 'lib/rails_admin/config.rb', line 269 def reset_model(model) key = model.kind_of?(Class) ? model.name.to_sym : model.to_sym @registry.delete(key) end |
.visible_models ⇒ Object
Get all models that are configured as visible sorted by their weight and label.
277 278 279 280 281 |
# File 'lib/rails_admin/config.rb', line 277 def visible_models self.models.select {|m| m.visible? }.sort do |a, b| (weight_order = a.weight <=> b.weight) == 0 ? a.label.downcase <=> b.label.downcase : weight_order end end |