Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有什么方法可以id从使用friendly_id 修改的模型中获取真实列?
id
出于性能原因,我不想为它进行另一个数据库查询。
广义上来说friendly_id 修改to_param和find方法。接下来应该工作:
to_param
find
@affiche = Affiche.find(params[:id]) # params[:id] is a slug @id = @affiche.id
你试过attributes["id"]吗?例如:Model.first.attributes["id"]
attributes["id"]
Model.first.attributes["id"]