Rails Catch All Route URL Helpers?
Posted
by viatropos
on Stack Overflow
See other posts from Stack Overflow
or by viatropos
Published on 2010-05-18T00:15:22Z
Indexed on
2010/05/18
0:20 UTC
Read the original article
Hit count: 726
ruby-on-rails
|routes
If I have a catch-all-route like this:
match '*request_path' => "pages#show", :as => :page
...and the pages can be arbitrarily nested, how do I make it so I can use the url helper methods?
If I have a page structure like this:
/about
/about/people
/about/story
/about/story/in-depth
Then I want to be able to write page_path(@page)
and get /about/story/in-depth
for the hypothetical "In Depth Story" page. But instead I'm just getting /in-depth
.
If I override Page#to_param
, and do something like this:
def to_param
result = ""
if parent
result << parent.to_param
result << "/"
end
result << super
end
... it returns an encoded string like this:
/about%2Fstory%2Fin-depth
Is there a way to make this work?
© Stack Overflow or respective owner