Skip to content

Instantly share code, notes, and snippets.

@jameslafa
Forked from bbonamin/event.rb
Last active July 5, 2019 23:32
Show Gist options
  • Save jameslafa/6455256 to your computer and use it in GitHub Desktop.
Save jameslafa/6455256 to your computer and use it in GitHub Desktop.
Handle translations with Globalize3 in Active Admin with Rails 4
#app/models/event.rb
class Event < ActiveRecord::Base
translates :title, :description, :summary
has_many :event_translations
accepts_nested_attributes_for :event_translations, :allow_destroy => true
end
#app/models/event_translation.rb
class EventTranslation < ActiveRecord::Base
belongs_to :event
validates_uniqueness_of :locale, :scope => :event_id
end
#app/admin/events.rb
ActiveAdmin.register Event do
params.permit project: [:date, :event_translations_attributes => [:title, :description, :summary, :locale, :id]]
index do
column :title
column :description
column :summary
default_actions
end
form do |f|
f.inputs :event do
f.input :date, :as => :datepicker
end
f.inputs :traductions do
f.has_many :event_translations do |g|
g.input :locale, :as => :select, :collection => I18n.available_locales
g.input :title
g.input :description
g.input :summary
end
end
f.actions
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment