Sami Sami - 11 months ago 63
Ruby Question

Can't overwrite the active admin default redirect path

I am using active admin in my application. In my controller, I have an action update with

function. But while updating, it threw me an error.

Render and/or redirect were called multiple times in this action. Please note that you may only call render or redirect, and at most once per action. Also note that neither redirect nor render terminates execution of the action, so if you want to exit an action after redirecting, you need to do something like
redirect_to(...) and return

def update
@user = User.find(params[:id])
redirect_to user_path(@user)

I tried

  1. only redirect_to

  2. redirect_to() and return

but nothing works.

before_filter :only =>[:create,:update] do
if self.action_name.to_sym == :create
@user =[:user])
@user = User.find(params[:id])

Answer Source

What is your purpose? Why you use mailers.notify(@user).deliver inside the update action?

  1. Move the notification to after_update filter in your User model, smth like this:

    after_update :send_notifications
    def send_notifications 
  2. Change the update method to smth like this:

    def update
      super do |format|
        redirect_to user_path(@user), notice: "Your notice message" and return if resource.valid?