2

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?

Goro
  • 990
  • 8
  • 7

2 Answers2

5

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
PrivateUser
  • 4,474
  • 12
  • 61
  • 94
2
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

Amr Arafat
  • 469
  • 3
  • 8
  • Thanks, I do understand the difference, but my question is if there is a reason not to just use `_url` all the time? Aside from just page size (which seems trivial). – Goro Mar 14 '14 at 21:32
  • It is just a convention to use "URL" when you need the absolute path and "path" otherwise. It's like starting the name of a model with capital letters. – Amr Arafat Mar 14 '14 at 21:41