user
user

Reputation: 1381

Active admin redirect to_back doesn't work

Why my redirect_to :back doesn't work? it just redirect to the same page.

my method

controller do

      def update
      update! do |success, failure|
        success.html { redirect_to :back }
      end
    end

  end

my request.refererreturns me my current path

Upvotes: 1

Views: 2197

Answers (3)

Eli R.
Eli R.

Reputation: 188

I found that the following works:

redirect_backwards_or_to_root

https://www.rubydoc.info/github/gregbell/active_admin/ActiveAdmin%2FBaseController%2FAuthorization:redirect_backwards_or_to_root

Rails 6, ActiveAdmin 2.7

Upvotes: 1

Kevin Grant
Kevin Grant

Reputation: 2351

I had good success in my use case url_for(:back). I specifically used it like this, but I would guess it works in other places

form do |f|
  f.actions do
    f.action :submit
    f.cancel_link(url_for(:back))
  end
end

Upvotes: 3

syafiq faiz
syafiq faiz

Reputation: 188

I know this is old. I was trying to solve the same issue. And found the way to do it. So I share it here.

Based on this code in here

This is how we do redirect back in ActiveAdmin

ActiveAdmin::Dependency.rails.redirect_back self, active_admin_root

Hope that help.

Upvotes: 0

Related Questions