Skip to content

Instantly share code, notes, and snippets.

@jirikolarik
Last active December 17, 2015 23:38
Show Gist options
  • Save jirikolarik/5690118 to your computer and use it in GitHub Desktop.
Save jirikolarik/5690118 to your computer and use it in GitHub Desktop.
Globalize3 + RailsAdmin
# app/models/page.rb
class Page < ActiveRecord::Base
validates :translations, presence: :true
translates :name, :content
accepts_nested_attributes_for :translations, allow_destroy: true
mount_uploader :image, ImageUploader
def to_param
"#{id} #{translation.name}".parameterize
end
end
# config/initializers/rails_admin.rb
# RailsAdmin config file. Generated on November 22, 2012 00:33
# See github.com/sferik/rails_admin for more informations
RailsAdmin.config do |config|
config.model 'Page' do
include_all_fields
list do
field :name
field :image
field :created_at do
column_width 200
end
end
end
config.model 'Page::Translation' do
visible false
field :name
field :locale, :enum do
enum_method do
:locale_enum
end
end
field :content, :ck_editor
end
end
# app/models/page/translation.rb
class Page::Translation < Globalize::ActiveRecord::Translation
validates :name, length: { maximum: 255 }, presence: true
validates :locale, presence: true, uniqueness: { scope: :page_id }
def locale_enum
I18n.available_locales
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment