_path vs. _url

In the "Ruby on Rails tutorial" website: http://railstutorial.org/chapters/filling-in-the-layout#sec:rails_routes, section 5.2.2: Rails routes, it was mentioned that:

match '/about', :to => 'pages#about'

Creates the following "named routes" for use in the controllers and views:

about_path => '/about' about_url => 'http://localhost:3000/about

After that, in section 5.2.3: Named routes:

"#" in: <%= link_to "About", '#' %>

Was replaced by: <%= link_to "About", about_path %>

From this thing, why did I use "about_path" here and NOT "about_url"? Are they differeny then?

So, does "about_path" denote the controller's "action"?

Thanks.

As you seem to have already discovered, the _url helper contain the domain, while the _path helpers do not.

Tim Shaffer wrote in post #972300:

In this case, how do we read:

match '/about', :to => 'pages#about'

I mean, what does the preceding statement say? Where is the URL here?

Thanks.

In this case, how do we read:

match '/about', :to => 'pages#about'

I mean, what does the preceding statement say? Where is the URL here?

The host and protocol bit are are about allowing the browser to talk to the right url - once the request has made it to your server, only the path matters (unless you've got some account as subdomain stuff going on) A lot of the time in your app you only need the _path helpers, because you're just linking between pages in your app (although it wouldn't hurt to use the _url helpers). Sometimes you need a full url (eg for putting links in an email) and so those helpers are there too.

Fred

Thanks Fred.