Friendly_id 和真实 ID [英] friendly_id and real id

查看:44
本文介绍了Friendly_id 和真实 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从使用friendly_id修改的模型中获取真正的id列?

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.

推荐答案

从广义上讲,friendly_id 修改了 to_paramfind 方法.接下来应该工作:

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

这篇关于Friendly_id 和真实 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆