Goro
Goro

Reputation: 998

Is there a technical reason not to use _url instead of _path in a Rails URL?

It seems like the general consensus is to use resource_path in URLs unless there's an explicit reason to use resource_url (like linking to/away from an SSL page, or a different subdomain).

I've run into bugs from time to time from using _path, so don't use it anymore, but when I googled this, most people say to use _path unless it's necessary to use _url. Is there any particular reason that I should not be doing this, or is it just bad form?

Upvotes: 2

Views: 182

Answers (2)

PrivateUser
PrivateUser

Reputation: 4524

As a rule of thumb

  • Use _path for internal links
  • Use _url for external and CDN type links

Pros of using _path

  • Hassle free domain migration
  • Faster page loading since you are reducing the page size

Upvotes: 5

Amr Arafat
Amr Arafat

Reputation: 489

root_url => http://localhost:3000/
root_path => /

employees_url => http://localhost:3000/employees
employees_path  # => /employees

For more details check these links out: http://smalltawc.blogspot.de/2013/02/difference-between-url-and-path-in.html http://viget.com/extend/rails-named-routes-path-vs-url

Upvotes: 2

Related Questions