Skip to content

Commit

Permalink
fixup! f5cb71a headings
Browse files Browse the repository at this point in the history
  • Loading branch information
garethrees committed Feb 24, 2015
1 parent 9ca425d commit 3c77b85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
25 changes: 21 additions & 4 deletions app/controllers/admin_public_body_headings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ def update
redirect_to edit_admin_heading_path(@heading)
else
I18n.available_locales.each do |locale|
@heading.translations.find_or_initialize_by_locale(locale)
if locale == I18n.default_locale
next
end

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

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

if !@heading.translations.where(:locale => locale).first && translation_params
@heading.translations.build(translation_params)
end

end
render :action => 'edit'
end
Expand Down Expand Up @@ -57,13 +70,17 @@ def create
redirect_to admin_categories_url
else
I18n.available_locales.each do |locale|
if locale == I18n.default_locale
@heading.translations.build(:locale => locale)
next
end

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

if !@heading.translations.where(:locale => locale).first && translation_params
@heading.translations.build(translation_params)
else
@heading.translations.build(:locale => locale)
end
end
render :action => 'new'
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin_public_body_headings/_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">
<% @heading.translations.each do |translation| %>
<% @heading.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 @@ -13,7 +13,7 @@
<% end %>
</ul>
<div class="tab-content">
<% @heading.translations.each do |translation| %>
<% @heading.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_heading', @heading do |t| %>
<%= render :partial => 'locale_fields', :locals => { :t => t, :locale => translation.locale } %>
Expand Down

0 comments on commit 3c77b85

Please sign in to comment.