views:

95

answers:

1

I'm trying to set up named routes for page:

  • www.myhost.com/blog/about

    (map.about '/about', :controller => 'page', :action => 'about')

And I have another route for a resource:

  • www.myhost.com/blog/post/3

    (map.resources :posts)

Now I don't know how should I link to "about" page. If I use

  • a) <%= link_to 'About', about_url %> or
  • b) <%= link_to 'About', 'about' %>

It works fine only when I go to blog/posts and blog/about. When I open blog/post/1, then the link to about page gets an url blog/post/about.

How can I force it to make an absolute path from the application root?

A: 

HTML output for (a) and (b) should be like this. The issue will occur only on using method (b).

a)

<a href="http://127.0.0.1:3000/about"&gt;About&lt;/a&gt;

b)

<a href="about">About</a>

if you need the absolute path from application root, you can pass about_path as the second argument to the link_to helper.(<%= link_to 'About', about_path %>). That will produce your links as shown below.

<a href="/about">About</a>
randika
I thought I tried with about_url, but now testing it for the second time - it works!
Karl