문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top