I have a page model that I want to find using the handle that I create from the title.
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
In my controller, I have:
def show
@page = Page.find_by_handle(params[:id])
end
I am doing the same with another model and it works fine, but not with the page. I keep getting this error:
ActiveRecord::RecordNotFound in
PagesController
Couldn't find Page with ID=test
Where testis the page handle. I feel that it worked just a few days ago when I created the model, so I'm not sure what could have changed to cause the problem. Perhaps the ultimate /?
Here is the log:
Started GET "/pages/test" for 127.0.0.1 at 2011-05-28 11:53:49 -0400
Processing by PagesController
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):
source
share