Skip to content

Instantly share code, notes, and snippets.

@bbonamin
Created December 23, 2011 20:59
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save bbonamin/1515338 to your computer and use it in GitHub Desktop.
Save bbonamin/1515338 to your computer and use it in GitHub Desktop.
Globalize3 implementation on ActiveAdmin with nested forms
#app/models/event.rb
class Event < ActiveRecord::Base
translates :title, :description
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
index do
column :title
column :description
default_actions
end
filter :title
filter :description
filter :date
form do |f|
f.inputs "Evento" do
f.input :date, :as => :datepicker
f.input :show_date, :as => :datepicker
end
f.inputs "Traducciones" do
f.has_many :event_translations do |g|
g.input :locale, :as => :radio, :collection => LANGUAGES
g.input :title
g.input :description, :as => :string
end
end
f.buttons
end
end
@massayoshi
Copy link

Love this implementation. Worked like a charm!

@ohshhh
Copy link

ohshhh commented Feb 2, 2014

works, yeap.

@besi
Copy link

besi commented Jul 9, 2014

The following Gem does a lot of the work for you:

gem "activeadmin-globalize", github: 'stefanoverna/activeadmin-globalize', branch: 'master'

https://github.com/stefanoverna/activeadmin-globalize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment