2013-02-12 71 views

回答

1

下面是從模型訪問發電機的一種選擇。有了這個,你可以在你的表單中加入:url_name或任何你想稱之爲的東西。在我的情況下,它被設置,所以如果沒有輸入字符串,它將url_name設置爲別的東西。

Class Foo < ActiveRecord::Base 

    has_friendly_id :url_name, :use_slug => true, :approximate_ascii => true 

    attr_accessible :url_name 

    def url_name 
    read_attribute(:url_name) || "some other default" 
    end 

end 

此外,這是年紀大一點的,但對FriendlyID結帳這個railscast

+0

感謝的更多信息!它幫助我找到了我想要的解決方案! ;) – 2013-02-12 15:45:43