如何使用find_by请求而非所有操作的ID自定义ActiveAdmin [英] How to custom ActiveAdmin using find_by request instead of ID for all actions
问题描述
只是将ActiveAdmin添加到我的应用程序中,我在使用show / edit / destroy操作时遇到问题,因为我的链接不是指向ID,而是指向用户名(为了使用户更容易理解)。
ActiveAdmin正确创建我的链接,例如:
编辑链接:
http:// localhost :3000 / admin / users / paul / edit(其中paul是用户名)
在这种情况下,我得到:
找不到ID = paul的用户
原因当然是Paul不是ID,而是用户名。
我如何自定义ActiveAdmin以像我的应用程序中那样使用find_by_name(params [:id])进行所有动作显示/编辑/删除。
在其他模型中,我有一个所谓的 SID,它是生成的盐腌ID,并且我也想将find_by_sid(params [:id])用于其他模型。 p>
非常感谢。
干杯。
这将在app / admin / user.rb中完成工作:
ActiveAdmin.register用户执行
before_filter:only => [:show,:edit,:update,:destroy] do
@user = User.find_by_name(params [:id])
结束
结束
just adding ActiveAdmin to my app, i got a problem using show/edit/destroy action cause my link doesn't point to ID but to users name (in order to be more readable for user).
ActiveAdmin correctly create my link like :
edit link :
http://localhost:3000/admin/users/paul/edit (where paul is the user name)
in that case i get :
Couldn't find User with ID=paul
cause of course Paul is not the id but the user name.
How can i custom ActiveAdmin to use find_by_name(params[:id]) like in my application for all the action show/edit/delete.
In other model i got a so called "SID" wich is a generated salted ID and i would like to use also the find_by_sid(params[:id]) as well for other models.
Thank's a lot.
Cheers..
This will do the job in the app/admin/user.rb :
ActiveAdmin.register User do
before_filter :only => [:show, :edit, :update, :destroy] do
@user = User.find_by_name(params[:id])
end
end
这篇关于如何使用find_by请求而非所有操作的ID自定义ActiveAdmin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!