11175
(-- --)
May 31, 2008, 5:02am
1
I have a route like so:
map.resources :articles
And I need to be able to have a URL like:
/article/:id/:slug
Is there any way to do this without messing with view code? I've looked
around at route documentation and code but can't wrap my head around it.
I know there's the to_param way to get "id-slug" but I am porting my app
from PHP to Rails and really need to preserve my URLs.
11175
(-- --)
May 31, 2008, 9:51am
2
*Note* Updated to Rails 2.1 as I needed to use a few things from there,
perhaps there are methods in 2.1 that could help with this?
11175
(-- --)
June 1, 2008, 9:24pm
4
11175
(-- --)
June 1, 2008, 9:25pm
5
11175
(-- --)
June 1, 2008, 10:17pm
6
Rails Terrorist wrote:
And also this url :
NameBright - Coming Soon
Reinhart
I don't think either of those URL's really answer my question?
AndyV
(AndyV)
June 1, 2008, 11:39pm
7
The whole routing system leans on the to_param method of
ActiveRecord. With that in mind, I'd suggest trying to override
Article#to_param:
class Artice < ActiveRecord::Base
...
def to_param
"#{id}/#{slug}"
end
end
That way, the article will include both it's id and slug when it's
used to create a url. It's a bit of a hack, but it might work.
11175
(-- --)
June 1, 2008, 11:43pm
8
Andy, thanks for the help. I had tried that before but it actually
sanitizes the html for the url, so its something like
article/100%XXtitle-of-article
11175
(-- --)
June 2, 2008, 8:45am
9
Nathan W. wrote:
Andy, thanks for the help. I had tried that before but it actually
sanitizes the html for the url, so its something like
article/100%XXtitle-of-article
You should read carefully my link because what Andi explained to you was
described in my link :
http://earthcode.com/blog/2007/01/to_param_still_works_with_rest.html
Reinhart
11175
(-- --)
June 2, 2008, 9:04am
10
Right, I understand that technique and I wrote in my original post that
I specifically *dont* want to do that.. Also your links above were
wrongly done..
Is there a way to update, say, article_path, to output this result with
the '/'?