diff options
author | David Cabo <david@calibea.com> | 2011-08-17 11:02:40 +0200 |
---|---|---|
committer | David Cabo <david@calibea.com> | 2011-08-23 23:45:23 +0200 |
commit | 7f3d321e8da99d0204b66161d9f00381ac24ad2d (patch) | |
tree | d8bc78df7de1d5f392f6829bd9f1fe571404db6e /app/controllers/admin_public_body_controller.rb | |
parent | 6af5f5cba5cf3c8478d676170faa66bca0ff90ab (diff) |
Refactor fixes to #142 and #143, new implementation much simpler to understand
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 |