-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Base configuration
The configuration in app/initializer/rails_admin.rb
is executed at startup time, once.
Rake tasks that load environment don't execute RailsAdmin initializer's block, for performance and DB migration status compatibility.
You can force it (true or false):
SKIP_RAILS_ADMIN_INITIALIZER=false rake mytask
Set the application name:
RailsAdmin.config do |config|
config.main_app_name = ["Cool app", "BackOffice"]
end
# or somethig more dynamic
RailsAdmin.config do |config|
config.main_app_name = Proc.new { |controller| [ "Cool app", "BackOffice - #{controller.params[:action].try(:titleize)}" ] }
end
Locale
If your default_local is different from :en, set your default locale at the beginning of the file:
require 'i18n'
I18n.default_locale = :de
current_user method
The current_user is usually inferred from your Devise settings and added to your initilizer file automatically.
If needed, it can be customized as such:
config.current_user_method { current_<%= @model_name %> }
Authentication (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 on the default user scope.
If you use devise, this will authenticate the same as authenticate_user!
Example Devise admin:
config.authenticate_with do
authenticate_admin!
end
Example Custom Warden:
``ruby config.authenticate_with do warden.authenticate! :scope => :paranoid end
To disable authentication, pass an empty block:
```ruby
RailsAdmin.config do |config|
config.authenticate_with {}
end
Authorization
Use cancan https://github.com/ryanb/cancan for authorization:
config.authorize_with :cancan
Or use simple custom authorization rule:
config.authorize_with do
redirect_to root_path unless warden.user.is_admin?
end
ActiveModel's :attr_acessible :attr_protected
Default is :default
config.attr_accessible_role { :default }
_current_user is accessible in the block if you need to make it user specific:
config.attr_accessible_role { _current_user.role.to_sym }