如一個about控制器內代碼以下: ruby
class AboutController < ApplicationController def connect end end
用 link_to '聯繫咱們' , connect_path 網站
生成的HTML代碼爲 <a href="/about/connect">聯繫咱們</a> url
而用 link_to '聯繫咱們' , connect_url spa
生成的HTML代碼爲 <a href="http://localhost:3000/about/connect">聯繫咱們</a> code
可見path方法生成的是相對路徑,而url方法生成的絕對路徑 it
在視圖中通常使用path io
關於url的用法: class
You need to use an absolute URI when linking to an SSL site from a non-SSL site, and vice versa.當你從一個沒使用SSL連接的網站到使用SSL的網站的時候須要用絕對路徑,反之亦然。
You need to use an absolute URI when creating a redirect (e.g. with redirect_to.)當在控制器裏面使用轉向(如redirect_to方法)的時候應該使用絕對路徑
(結束) rsa