Skip to content

Commit

Permalink
Build translations before attempting to save
Browse files Browse the repository at this point in the history
  • Loading branch information
garethrees committed Feb 26, 2015
1 parent 222dda9 commit e4e1e33
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions app/controllers/admin_public_body_categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def update
def create
I18n.with_locale(I18n.default_locale) do
@category = PublicBodyCategory.new(params[:public_body_category])
# Build a translation for the default locale as it isn't available
# until the parent record is persisted
@category.translations.build(:locale => I18n.default_locale,
:title => params[:public_body_category][:title],
:description => params[:public_body_category][:description])

if @category.save
# FIXME: This can't handle failure (e.g. if a PublicBodyHeading
Expand All @@ -95,20 +100,6 @@ def create
flash[:notice] = 'Category was successfully created.'
redirect_to admin_categories_path
else
I18n.available_locales.each do |locale|
if locale == I18n.default_locale
@category.translations.build(:locale => locale)
next
end

translation_params = params[:public_body_category].
fetch(:translations_attributes, {}).
fetch(locale, nil)

if !@category.translations.where(:locale => locale).first && translation_params
@category.translations.build(translation_params)
end
end
render :action => 'new'
end
end
Expand Down

0 comments on commit e4e1e33

Please sign in to comment.