How do I use instance variables, defined in the controller, in the view with ActiveAdmin?

Just in case someone else stumbles upon this:

controller.instance_variable_get(:@user)

should work as well.


There is controller in active admin, despite this you can not pass instance variable to arbre part. But you can use params hash for this:

ActiveAdmin.register User do
  controller do
    def show
      params[:user] = User.find(params[:id])
      show! 
    end
  end

  show do
    attributes_table do
      row "User" do
        link_to params[:user].display_name, user_path(params[:user].slug) 
      end
    end
  end
end

P.S.: If you don't want to change params, then all instance variables are stored in @arbre_context.assigns. You may also do like:

link_to @arbre_context.assigns[:user].display_name, user_path(@arbre_context.assigns[:user].slug) 

Instance variables are defined as helper methods. If you have that defined in your controller, you can access it. Alternatively, you can simply call resource, which will have reference to the active record object.

ActiveAdmin.register User do
  controller do
    def show
      @user = User.find(params[:id])
      show! 
    end
  end

  show do
    attributes_table do
      row "User" do
        # note that your have access to `user` as a method.
        link_to user.display_name, user_path(user.slug) 
      end
    end
  end
end