3
我有一個頁面模型,我想通過我從標題創建的句柄找到。在rails中「to_param」的問題
class Page < ActiveRecord::Base
belongs_to :user
validates_presence_of :title
def to_param
handle
end
def self.make_url_safe(string)
handle = string.titleize.gsub(/ /,'').underscore.dasherize[0..35]
"#{handle}/"
end
end
在我的控制,我有:
def show
@page = Page.find_by_handle(params[:id])
end
我在做同樣的事情與其他模型和它的正常工作,但不與頁面。我不斷收到此錯誤:
ActiveRecord::RecordNotFound in
PagesController#show
Couldn't find Page with ID=test
哪裏test
是頁面的手柄。我感覺就像前幾天我創建模型時一樣,所以不確定可能導致問題的原因。也許尾隨/
?
這裏的日誌:
Started GET "/pages/test" for 127.0.0.1 at 2011-05-28 11:53:49 -0400
Processing by PagesController#show as HTML
Parameters: {"id"=>"test"}
Page Load (0.2ms) SELECT "pages".* FROM "pages" WHERE ("pages"."id" = 0) LIMIT 1
Completed in 12ms
ActiveRecord::RecordNotFound (Couldn't find Page with ID=test):
你使用康康? – apneadiving 2011-05-28 16:22:34
它似乎有一個前過濾器去一個。你有沒有在控制器中設置任何東西? – 2011-05-28 17:30:25
Cancan的'load_and_authorize'確實加載導致這種錯誤的數據。 – apneadiving 2011-05-28 17:45:39