From 158cc1d2d0f289008059a48be3d18cf91df9a4d8 Mon Sep 17 00:00:00 2001 From: David Carlos Date: Thu, 11 Dec 2014 13:47:26 +0000 Subject: [PATCH] Refactors edit_institution method in mpog_software_plugin_myprofile_controller. --- controllers/mpog_software_plugin_myprofile_controller.rb | 56 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/controllers/mpog_software_plugin_myprofile_controller.rb b/controllers/mpog_software_plugin_myprofile_controller.rb index 3b25218..c2d7c4d 100644 --- a/controllers/mpog_software_plugin_myprofile_controller.rb +++ b/controllers/mpog_software_plugin_myprofile_controller.rb @@ -6,37 +6,15 @@ class MpogSoftwarePluginMyprofileController < MyProfileController def edit_institution @show_sisp_field = environment.admins.include?(current_user.person) - @estate_list = NationalRegion.find(:all, :conditions => - {:national_region_type_id => 2}, - :order=>"name") + @estate_list = NationalRegion.find(:all, :conditions => + { :national_region_type_id => 2 }, + :order=>'name') @institution = @profile.institution - - if request.post? - @institution.community.update_attributes(params[:community]) - @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature)) - - if @institution.type == "PublicInstitution" - begin - govPower = GovernmentalPower.find params[:institutions][:governmental_power] - govSphere = GovernmentalSphere.find params[:institutions][:governmental_sphere] - jur_nature = JuridicalNature.find params[:institutions][:juridical_nature] - - @institution.juridical_nature = jur_nature - @institution.governmental_power = govPower - @institution.governmental_sphere = govSphere - @institution.save - rescue - @institution.errors.add(:governmental_fields, _("Could not find Governmental Power or Governmental Sphere")) - end - end - - flash[:errors] = @institution.errors.full_messages unless @institution.valid? - end + update_institution if request.post? end def new_software - @errors = [] software_template = Community["software"] if (!software_template.blank? && software_template.is_template) @@ -72,6 +50,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController end else + @errors = [] @errors |= @community.errors.full_messages @errors |= @software_info.errors.full_messages @errors |= @license_info.errors.full_messages @@ -155,5 +134,30 @@ class MpogSoftwarePluginMyprofileController < MyProfileController def community_must_be_approved end + private + + def update_institution + @institution.community.update_attributes(params[:community]) + @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature)) + if @institution.type == "PublicInstitution" + begin + governmental_updates + rescue + @institution.errors.add(:governmental_fields, _("Could not find Governmental Power or Governmental Sphere")) + end + end + flash[:errors] = @institution.errors.full_messages unless @institution.valid? + end + + def governmental_updates + govPower = GovernmentalPower.find params[:institutions][:governmental_power] + govSphere = GovernmentalSphere.find params[:institutions][:governmental_sphere] + jur_nature = JuridicalNature.find params[:institutions][:juridical_nature] + + @institution.juridical_nature = jur_nature + @institution.governmental_power = govPower + @institution.governmental_sphere = govSphere + @institution.save + end end -- libgit2 0.21.2