Created
March 26, 2012 11:53
-
-
Save Slotos/2204617 to your computer and use it in GitHub Desktop.
ActiveAdmin Globalize form
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
module Formtastic | |
class FormBuilder | |
def globalize_inputs(*args, &proc) | |
index = options[:child_index] || "#{self.object.class.to_s}-#{self.object.object_id}" | |
linker = ActiveSupport::SafeBuffer.new | |
fields = ActiveSupport::SafeBuffer.new | |
::I18n.available_locales.each do |locale| | |
linker << self.template.content_tag(:li, | |
self.template.content_tag(:a, | |
::I18n.t('translation', :locale => locale), | |
:href => "#lang-#{locale}-#{index}" | |
) | |
) | |
fields << self.template.content_tag(:div, | |
self.semantic_fields_for(*(args.dup << self.object.translation_for(locale)), &proc), | |
:id => "lang-#{locale}-#{index}" | |
) | |
end | |
linker = self.template.content_tag(:ul, linker, :class => "language-selection") | |
self.template.content_tag(:div, linker + fields, :class => "language-tabs-#{index}") + self.template.content_tag(:script, "$('.language-tabs-#{index}').tabs();", :type => "text/javascript") | |
end | |
end | |
end | |
module ActiveAdmin | |
class FormBuilder | |
def globalize_inputs(*args, &proc) | |
content = with_new_form_buffer { super } | |
form_buffers.last << content.html_safe | |
end | |
end | |
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
ActiveAdmin.register Gallery do | |
actions :index, :new, :create, :edit, :update, :destroy, :show | |
form do |f| | |
f.globalize_inputs :translations do |lf| | |
lf.inputs :title, :twitter_title, :slug, :lead, :text, :locale do | |
lf.input :title | |
lf.input :description | |
lf.input :locale, :as => :hidden | |
end | |
end | |
f.has_many :photos do |photo| | |
photo.inputs do | |
photo.input :image, :as => :file, :label => "Image",:hint => photo.object.image.nil? ? photo.template.content_tag(:span, "No Image Yet") : photo.template.image_tag(photo.object.image.url(:thumb)) | |
end | |
photo.globalize_inputs :translations do |lp| | |
lp.inputs do | |
lp.input :description | |
lp.input :locale, :as => :hidden | |
end | |
end | |
end | |
f.buttons | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment