diff options
Diffstat (limited to 'app/controllers/admin_public_body_controller.rb')
-rw-r--r-- | app/controllers/admin_public_body_controller.rb | 72 |
1 files changed, 16 insertions, 56 deletions
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb index 61e4aec54..bd85f6eed 100644 --- a/app/controllers/admin_public_body_controller.rb +++ b/app/controllers/admin_public_body_controller.rb @@ -82,77 +82,37 @@ class AdminPublicBodyController < AdminController end def new - @locale = self.locale_from_params() - PublicBody.with_locale(@locale) do - @public_body = PublicBody.new - render - end - end - - def update_localized_attributes(public_body, params) - I18n.available_locales.each do |locale| - PublicBody.with_locale(locale) do - unless (attr_values = params["public_body_#{locale}"]).nil? - # 'publication_scheme' can't be null in the current DB schema - attr_values[:publication_scheme] = attr_values[:publication_scheme] || '' - public_body.attributes = attr_values - public_body.save! - end - end - end + @public_body = PublicBody.new + render end def create - # Start creating the public body in the default locale PublicBody.with_locale(I18n.default_locale) do - begin - ActiveRecord::Base.transaction do - params[:public_body][:last_edit_editor] = admin_http_auth_user() - @public_body = PublicBody.new(params[:public_body]) - @public_body.save! - - # Next, save the translations in the additional locales - update_localized_attributes(@public_body, params) - - flash[:notice] = 'PublicBody was successfully created.' - redirect_to admin_url('body/show/' + @public_body.id.to_s) - end - rescue ActiveRecord::RecordInvalid + params[:public_body][:last_edit_editor] = admin_http_auth_user() + @public_body = PublicBody.new(params[:public_body]) + if @public_body.save + flash[:notice] = 'PublicBody was successfully created.' + redirect_to admin_url('body/show/' + @public_body.id.to_s) + else render :action => 'new' end end end def edit - PublicBody.with_locale(I18n.default_locale) do - @public_body = PublicBody.find(params[:id]) - @public_body.last_edit_comment = "" - end - - # Additional locales (could remove the default, but won't make a difference) - I18n.available_locales.each do |locale| - instance_variable_set("@public_body_#{locale}", @public_body.translations.select{|t| t.locale==locale}.first) - end - + @public_body = PublicBody.find(params[:id]) + @public_body.last_edit_comment = "" render end def update - # Start updating the public body in the default locale PublicBody.with_locale(I18n.default_locale) do - begin - ActiveRecord::Base.transaction do - params[:public_body][:last_edit_editor] = admin_http_auth_user() - @public_body = PublicBody.find(params[:id]) - @public_body.update_attributes!(params[:public_body]) - - # Next, update the translations in the additional locales - update_localized_attributes(@public_body, params) - - flash[:notice] = 'PublicBody was successfully updated.' - redirect_to admin_url('body/show/' + @public_body.id.to_s) - end - rescue ActiveRecord::RecordInvalid + params[:public_body][:last_edit_editor] = admin_http_auth_user() + @public_body = PublicBody.find(params[:id]) + if @public_body.update_attributes(params[:public_body]) + flash[:notice] = 'PublicBody was successfully updated.' + redirect_to admin_url('body/show/' + @public_body.id.to_s) + else render :action => 'edit' end end |