Rails ActiveAdmin – 更改更新后的redirect_to
我有一个属于Car页面的Feature页面。 除了一件事,这正是我想要的。
在创建,更新或销毁之后,我希望将页面重定向到admin_car_path(car)
而不是默认的admin_car_feature_path(car,feature)
用于create和update以及admin_car_features_path(car)
。
我没有成功搜索到那个。
ActiveAdmin.register Car do end ActiveAdmin.register Feature do belongs_to :car end
TIA
以下是针对您的案例的更新操作的代码。 此代码转到features.rb – admin文件:
controller do def update update! do |format| format.html { redirect_to admin_cars_path } end end end
这会重定向到汽车索引页面。 所以你有这个想法。 对于创建和销毁操作也是如此。
正确的更新代码,无需跳过validation
controller do def update super do |success,failure| success.html { redirect_to collection_path } end end end
在当前时刻,接受的答案会导致忽略validation错误。
这适用于我使用最新版本的ActiveAdmin和Rails:
controller do def update update! do |format| format.html { redirect_to collection_path } if resource.valid? end end def create create! do |format| format.html { redirect_to collection_path } if resource.valid? end end end
Marcelo,我不确定我理解你的问题,但是不会把它放到update
,在你的控制器中create
和destroy
动作吗?
format.html { redirect_to redirect_address }
并根据需要制作redirect_address
。