Rails ActiveAdmin - 更改更新后的redirect_to
我有一个属于汽车页面的功能页面。这正是我想要的,除了一件事之外。
创建、更新或销毁后,我希望页面重定向到 admin_car_path(car)
而不是默认的 admin_car_feature_path(car,feature)
用于创建和更新以及 <代码>admin_car_features_path(汽车)。
我没有成功地寻找那个。
ActiveAdmin.register Car do
end
ActiveAdmin.register Feature do
belongs_to :car
end
TIA
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
正确的更新代码而不跳过验证
right code for updating without skipping validation
以下是您的案例的更新操作代码。此代码转到 features.rb - 管理文件:
这会重定向到汽车索引页面。所以你有这个想法。创建和销毁操作也是如此。
Here is the code for update action for your case. This code goes to the features.rb - admin file:
This redirects to the cars index page. So you have the idea. Same for create and destroy actions.
目前接受的答案会导致忽略验证错误。
这对我来说适用于最新版本的 ActiveAdmin 和 Rails:
At the current moment accepted answer leads to ignoring validation errors.
This works for me with the latest versions of ActiveAdmin and Rails:
这是一个也适用于
create_another
的解决方案,使用parent
和child
作为模型名称。此解决方案假设您将子项显示为父项的一部分(例如通过
table_for
),因此您不需要子项的index
方法。在资源覆盖控制器的
smart_resource_url
和index
方法中:Here is a solution that also works with
create_another
, usingparent
andchild
for model names.This solution assumes that you show children as part of parent (e.g. via
table_for
) so you do not need child'sindex
method.In resource override controller's
smart_resource_url
andindex
methods:当前的答案是跳过验证。其他一些答案有效,但部分正确(不正确使用
super
或手动验证资源)。创建和更新后使用 AA 进行重定向的最新“正确”方式:
Current answer is skipping validations. Some of the other answers are working but partially correct (incorrect use of
super
or manually validating resource).Most updated "proper" way to redirect with AA after create and udpate:
马塞洛,我不确定我是否理解您的问题,但不会将其放入控制器中的
update
、create
和destroy
操作中做这件事吗?并根据您的需要设置
redirect_address
。Marcelo, I'm not sure I understand your question, but wouldn't putting this into the
update
,create
anddestroy
actions in your controller do the trick?And make
redirect_address
whatever you need.