包括在塞ID我使用friendly_id寶石在我application.I漂亮的網址要像一個網址:
如何使用friendly_id
localhost:3000/posts/1/my-first-post
我想用friendly_id寶石,因爲我想這樣做使用歷史記錄模塊,以避免404個error.I都試過,但不能包括在我使用的slug.The代碼id爲如下:
class Post < ActiveRecord::Base
extend FriendlyId
friendly_id :pretty_url, use: [:slugged, :history]
def pretty_url
"#{id}/#{title}"
end
end
但它不包括在塞的ID 。而不是使用slu as,好像只使用標題一樣。
是的,我也試過了,但仍是ID沒有顯示。 – ananyo2012
你看到「-title」或「title」嗎?如果是前者,那麼你的id映射可能存在缺陷。如果是後者,那麼.... idk說實話 – Synergist
是的,我只是看到在網址slu「」標題「。 – ananyo2012