Skip to content

Commit

Permalink
Fix and refactor redirect_back_or_to
Browse files Browse the repository at this point in the history
  • Loading branch information
mayorova committed Nov 21, 2024
1 parent 62d393f commit 77a1734
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/services_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def create
def update
if integration_settings_updater_service.call(service_attributes: service_params.to_h, proxy_attributes: proxy_params.to_h)
flash[:notice] = t('flash.services.update.notice')
redirect_back_or_to :action => :settings
redirect_back_or_to({ action: "settings" })
else
flash.now[:error] = t('flash.services.update.error')
render action: params[:update_settings].present? ? :settings : :edit # edit page is only page with free form fields. other forms are less probable to have errors
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/buyers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ def destroy

def toggle_monthly_charging
account.settings.toggle!(:monthly_charging_enabled)
redirect_back(fallback_location: redirection_path)
redirect_back_or_to(redirection_path)
end

def toggle_monthly_billing
account.settings.toggle!(:monthly_billing_enabled)
redirect_back(fallback_location: redirection_path)
redirect_back_or_to(redirection_path)
end

def show
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/buyers/service_contracts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def destroy
flash[:error] = t('service_contracts.unsubscribe_failure')
end

redirect_back(fallback_location: admin_buyers_account_service_contracts_path(@account))
redirect_back_or_to(admin_buyers_account_service_contracts_path(@account))
end

def approve
Expand All @@ -83,7 +83,7 @@ def approve
flash[:error] = 'Cannot approve service contract.'
end

redirect_back(fallback_location: admin_buyers_account_service_contracts_path(@account))
redirect_back_or_to(admin_buyers_account_service_contracts_path(@account))
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/buyers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ def user_params
end

def redirect_back_or_show_detail
redirect_back(fallback_location: admin_buyers_account_user_path(account_id: user.account_id, id: user.id))
redirect_back_or_to(admin_buyers_account_user_path(account_id: user.account_id, id: user.id))
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def update

if type
@billing_strategy.change_mode(type)
redirect_back(fallback_location: admin_finance_billing_strategy_path)
redirect_back_or_to(admin_finance_billing_strategy_path)
else
render_error(:not_found)
end
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/master/providers/switches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ class SwitchesController < Master::Providers::BaseController

def update
status = @switch.allow ? :found : :not_modified
# Switch to `redirect_back_or_to` in Rails 7
redirect_back(fallback_location: back_url, status: status)
redirect_back_or_to(back_url, status: status)
end

def destroy
status = @switch.deny ? :found : :not_modified
# Switch to `redirect_back_or_to` in Rails 7
redirect_back(fallback_location: back_url, status: status)
redirect_back_or_to(back_url, status: status)
end

protected
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/provider/admin/applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def destroy
redirect_to provider_admin_applications_path
else
flash[:notice] = 'Not possible to delete application'
redirect_back(fallback_location: provider_admin_applications_path)
redirect_back_or_to(provider_admin_applications_path)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def edit; end
def update
if @page.update(permitted_params.fetch(:cms_template))
flash[:info] = 'Legal terms saved.'
redirect_back(fallback_location: { action: "edit", id: @page.id})
redirect_back_or_to({ action: "edit", id: @page.id})
else
render :edit
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/provider/admin/cms/versions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def revert
redirect_to polymorphic_path([:edit, :provider, :admin, @page])
else
flash[:error] = "Problem reverting version"
redirect_back(fallback_location: provider_admin_cms_template_version_path(@page, version))
redirect_back_or_to(provider_admin_cms_template_version_path(@page, version))
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/provider/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Provider::PasswordsController < FrontendController
before_action :passwords_allowed?

def new
return redirect_back(fallback_location: root_path), error: t('.has_password') if current_user.using_password?
return redirect_back_or_to(root_path), error: t('.has_password') if current_user.using_password?

reset_session_password_token
token = current_user.generate_lost_password_token
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sites/usage_rules_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def edit
def update
if @settings.update(params[:settings])
flash[:notice] = 'Settings updated.'
redirect_back(fallback_location: admin_site_settings_url)
redirect_back_or_to(admin_site_settings_url)
else
render :edit
end
Expand Down
4 changes: 2 additions & 2 deletions app/lib/forum_support/user_topics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def create
respond_to do |format|
flash[:notice] = 'You have successfully subscribed to the thread.' if @user_topic.save

format.html { redirect_back(fallback_location: forum_subscriptions_path) }
format.html { redirect_back_or_to(forum_subscriptions_path) }
end
end

Expand All @@ -41,7 +41,7 @@ def destroy
respond_to do |format|
flash[:notice] = 'You have successfully unsubscribed from the thread.'

format.html { redirect_back(fallback_location: root_path) }
format.html { redirect_back_or_to(root_path) }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def update
@cinstance.change_user_key!

flash[:notice] = 'The user key was regenerated.'
redirect_back(fallback_location: admin_application_user_key_path(@cinstance.id))
redirect_back_or_to(admin_application_user_key_path(@cinstance.id))
end

private
Expand Down

0 comments on commit 77a1734

Please sign in to comment.