Skip to content

Commit

Permalink
Merge pull request #10 from Sitata/select_locales
Browse files Browse the repository at this point in the history
Select locales via configuration.
  • Loading branch information
tiagogodinho committed May 16, 2015
2 parents d066033 + 182e492 commit 2ad5397
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions lib/localized_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,34 @@ module LocalizedFields

autoload :FormBuilder
autoload :Helpers


class << self

def configuration
@configuration ||= Configuration.new
end

def configuration=(config)
@configuration = config
end

def configure
yield(configuration)
end

end

class Configuration
attr_accessor :used_locales

def initialize
self.used_locales = I18n.available_locales
end
end



end

ActionView::Helpers::FormBuilder.send :include, LocalizedFields::Helpers::FormHelper
2 changes: 1 addition & 1 deletion lib/localized_fields/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def localized_fields(field = nil, options = {}, &block)
else
output = ''

I18n.available_locales.each do |language|
LocalizedFields.configuration.used_locales.each do |language|
output << @template.fields_for(object_name, @object, options.merge(builder: LocalizedFields::FormBuilder, language: language), &block)
end

Expand Down

0 comments on commit 2ad5397

Please sign in to comment.