Skip to content

Instantly share code, notes, and snippets.

@walidvb
Created May 20, 2016 16:23
Show Gist options
  • Save walidvb/18c4c23d369145605d3ec336d6cc4434 to your computer and use it in GitHub Desktop.
Save walidvb/18c4c23d369145605d3ec336d6cc4434 to your computer and use it in GitHub Desktop.
RailsAdmin config for translatable models
#### I18n
gem 'rails-i18n', '~> 4.0.0'
gem 'globalize'
gem 'rails_admin', github: 'sferik/rails_admin'
gem 'rails_admin_globalize_field'
class MyModel < ActiveRecord::Base
translates :your_fields
accepts_nested_attributes_for :translations, allow_destroy: true
end
# config/rails_admin.rb
RailsAdmin.config do |config|
config.main_app_name = [Rails.application.class.parent_name]
### Popular gems integration
I18n.default_locale = :en
I18n.available_locales = [:en, :fr]
## == Devise ==
config.authenticate_with do
warden.authenticate! scope: :user
end
config.current_user_method(&:current_user)
## == Cancan ==
# config.authorize_with :cancan
## == PaperTrail ==
# config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0
### More at https://github.com/sferik/rails_admin/wiki/Base-configuration
nested_only = %w{}
config.actions do
dashboard do
except nested_only
end
index do
end
new do
end
export
bulk_delete
show
edit
delete do
except nested_only
end
show_in_app do
except nested_only
end
## With an audit adapter, you can add:
# history_index
# history_show
end
## == Globalize ==
translated_models = []
config.included_models = ["User"].concat(translated_models.map{|model| [model, "#{model}::Translation"]}.flatten)
## == Globalize Translated Fields ==
translated_models.each do |model|
config.model model do
configure :translations, :globalize_tabs
end
config.model "#{model}::Translation" do
visible false
configure :locale, :hidden do
help ''
end
include_fields :locale, *Object.const_get(model).translated_attribute_names
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment