Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails ActiveAdmin - change the after update redirect_to

I have a Feature page that belongs to the Car page. That is working exactly how I want to, except for one thing.

After creating, updating or destroying, I want the page to be redirected to the admin_car_path(car) instead of the defaults admin_car_feature_path(car,feature) for create and update and admin_car_features_path(car).

I unsuccessfully searched for that.

ActiveAdmin.register Car do
end

ActiveAdmin.register Feature do
  belongs_to :car
end

TIA

like image 759
Marcelo Avatar asked Jan 28 '12 19:01

Marcelo


2 Answers

right code for updating without skipping validation

controller do
  def update
    super do |success,failure|
      success.html { redirect_to collection_path }
    end
  end
end
like image 60
nazar kuliyev Avatar answered Nov 05 '22 09:11

nazar kuliyev


Here is the code for update action for your case. This code goes to the features.rb - admin file:

controller do
  def update
    update! do |format|
      format.html { redirect_to admin_cars_path }
    end
  end
end

This redirects to the cars index page. So you have the idea. Same for create and destroy actions.

like image 27
kravc Avatar answered Nov 05 '22 08:11

kravc