friendly_id and real id

白昼怎懂夜的黑 提交于 2019-12-21 20:28:25

问题


Is there any way to get the real id column from a model that is modified with friendly_id?

I don`t want to make another db query for it, in performance reasons.


回答1:


Broadly speaking friendly_id modifies to_param and find methods. Next should work:

@affiche = Affiche.find(params[:id]) # params[:id] is a slug
@id = @affiche.id



回答2:


Have you tried attributes["id"]? e.g: Model.first.attributes["id"]



来源:https://stackoverflow.com/questions/7944908/friendly-id-and-real-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!