Refactoring organizations_controller.rb. Adding set_organization method (#3793)

for not repeating query code.
This commit is contained in:
Feruz Oripov 2019-08-23 05:54:53 +05:00 committed by Ben Halpern
parent 8acd1dc638
commit c0e1ad0e46

View file

@ -20,8 +20,7 @@ class OrganizationsController < ApplicationController
@user = current_user
@tab = "organization"
@tab_list = @user.settings_tab_list
@organization = Organization.find_by(id: organization_params[:id])
authorize @organization
set_organization
if @organization.update(organization_params.merge(profile_updated_at: Time.current))
flash[:settings_notice] = "Your organization was successfully updated."
@ -32,8 +31,7 @@ class OrganizationsController < ApplicationController
end
def generate_new_secret
@organization = Organization.find_by(id: organization_params[:id])
authorize @organization
set_organization
@organization.secret = @organization.generated_random_secret
@organization.save
flash[:settings_notice] = "Your org secret was updated"
@ -78,4 +76,9 @@ class OrganizationsController < ApplicationController
end
end
end
def set_organization
@organization = Organization.find_by(id: organization_params[:id])
authorize @organization
end
end