Skip to content

Commit

Permalink
fixup! 8e947a4 categories
Browse files Browse the repository at this point in the history
  • Loading branch information
garethrees committed Feb 24, 2015
1 parent 3c77b85 commit 6de375c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
24 changes: 20 additions & 4 deletions app/controllers/admin_public_body_categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,19 @@ def update
redirect_to edit_admin_category_path(@category)
else
I18n.available_locales.each do |locale|
@category.translations.find_or_initialize_by_locale(locale)
if locale == I18n.default_locale
next
end

next if @category.translations.map(&:locale).include?(locale)

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 => 'edit'
end
Expand All @@ -80,13 +92,17 @@ def create
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 translation_params

if !@category.translations.where(:locale => locale).first && translation_params
@category.translations.build(translation_params)
else
@category.translations.build(:locale => locale)
end
end
render :action => 'new'
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin_public_body_categories/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<div id="div-locales">
<ul class="locales nav nav-tabs">
<% @category.translations.each do |translation| %>
<% @category.translations.select{ |t| I18n.available_locales.include?(t.locale) }.sort_by{ |t| I18n.available_locales.index(t.locale) }.each do |translation| %>
<li>
<a href="#div-locale-<%= translation.locale.to_s %>" data-toggle="tab" >
<%= locale_name(translation.locale.to_s) || _("Default locale") %>
Expand All @@ -14,7 +14,7 @@
</ul>

<div class="tab-content">
<% @category.translations.each do |translation| %>
<% @category.translations.select{ |t| I18n.available_locales.include?(t.locale) }.sort_by{ |t| I18n.available_locales.index(t.locale) }.each do |translation| %>
<% if translation.locale.to_s == I18n.default_locale.to_s %>
<%= fields_for 'public_body_category', @category do |t| %>
<%= render :partial => 'locale_fields', :locals => { :t => t, :locale => translation.locale } %>
Expand Down

0 comments on commit 6de375c

Please sign in to comment.