Created
December 23, 2011 20:59
-
-
Save bbonamin/1515338 to your computer and use it in GitHub Desktop.
Globalize3 implementation on ActiveAdmin with nested forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/models/event_translation.rb | |
class EventTranslation < ActiveRecord::Base | |
belongs_to :event | |
validates_uniqueness_of :locale, :scope => :event_id | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following Gem does a lot of the work for you:
https://github.com/stefanoverna/activeadmin-globalize