Named routes _path vs _url

前端 未结 4 2057
借酒劲吻你
借酒劲吻你 2020-11-29 20:27

Rails provides named routes.

Routes helper can be called using path or url

eg from docs:

# and provide these named routes
root_url   # =>          


        
4条回答
  •  情歌与酒
    2020-11-29 20:39

    When you put a link in your own site, the domain part of the route is redundant, and adds to the page size, so you can just use the path part of the URL with the *_path helper. On the other hand, if the URL is to be consumed outside of your site, e.g. an email or an RSS feed, the whole URL is needed, so use the *_url helper.

提交回复
热议问题