diff options
author | Gareth Rees <gareth@mysociety.org> | 2015-01-29 15:49:34 +0000 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2015-03-18 12:37:59 +0000 |
commit | 673f94bba993d4f975a511ffd59424520060187c (patch) | |
tree | 9f66b0f9581008c0640b61c859a38f0a9125c8ac /app/controllers | |
parent | d109615206d456b0175d6c63c3c13fe74875f548 (diff) |
Fix translating Public Body Categories
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/admin_public_body_categories_controller.rb | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/app/controllers/admin_public_body_categories_controller.rb b/app/controllers/admin_public_body_categories_controller.rb index 5e305dde3..a86171c76 100644 --- a/app/controllers/admin_public_body_categories_controller.rb +++ b/app/controllers/admin_public_body_categories_controller.rb @@ -7,17 +7,39 @@ class AdminPublicBodyCategoriesController < AdminController def new @category = PublicBodyCategory.new - render :formats => [:html] + @category.build_all_translations + end + + def create + I18n.with_locale(I18n.default_locale) do + @category = PublicBodyCategory.new(params[:public_body_category]) + if @category.save + # FIXME: This can't handle failure (e.g. if a PublicBodyHeading + # doesn't exist) + if params[:headings] + params[:headings].values.each do |heading_id| + PublicBodyHeading.find(heading_id).add_category(@category) + end + end + flash[:notice] = 'Category was successfully created.' + redirect_to admin_categories_path + else + @category.build_all_translations + render :action => 'new' + end + end end def edit @category = PublicBodyCategory.find(params[:id]) + @category.build_all_translations @tagged_public_bodies = PublicBody.find_by_tag(@category.category_tag) end def update @category = PublicBodyCategory.find(params[:id]) @tagged_public_bodies = PublicBody.find_by_tag(@category.category_tag) + heading_ids = [] I18n.with_locale(I18n.default_locale) do @@ -43,6 +65,8 @@ class AdminPublicBodyCategoriesController < AdminController end added_headings.each do |heading_id| + # FIXME: This can't handle failure (e.g. if a + # PublicBodyHeading doesn't exist) PublicBodyHeading.find(heading_id).add_category(@category) end end @@ -51,29 +75,13 @@ class AdminPublicBodyCategoriesController < AdminController flash[:notice] = 'Category was successfully updated.' redirect_to edit_admin_category_path(@category) else + @category.build_all_translations render :action => 'edit' end end end end - def create - I18n.with_locale(I18n.default_locale) do - @category = PublicBodyCategory.new(params[:public_body_category]) - if @category.save - if params[:headings] - params[:headings].values.each do |heading_id| - PublicBodyHeading.find(heading_id).add_category(@category) - end - end - flash[:notice] = 'Category was successfully created.' - redirect_to admin_categories_path - else - render :action => 'new' - end - end - end - def destroy @locale = self.locale_from_params I18n.with_locale(@locale) do |