Rails routes: _url vs _path

Here below you can find the pros and cons of _url and _path helpers.

  • _url provides a link accompanied with the protocol and the host name (eg. http://webspirit.gr/posts/:slug)
    So, use _url when the case is:
    1. redirect_to
    2. respond_to do |format|
        format.html { redirect_to post_url }
      end

    3. Redirect to another domain
    4. Email templates
  • _path is used the rest of the time, with links to forms and other pages inside the app
    Using _url will also work but it's a bad practice because you're adding useless information.

Reference: Rails guides

comments powered by Disqus