-
-
Save jameslafa/6455256 to your computer and use it in GitHub Desktop.
Handle translations with Globalize3 in Active Admin with Rails 4
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, :summary | |
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 | |
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