2010-12-07 33 views
0

使用rails url助手,我將如何鏈接到我的home_controller.rb的聯繫動作?我將如何鏈接到我的home_controller.rb的聯繫行爲?

  1. 如何生成的鏈接
  2. 如何剛剛得到的路徑?
  3. 如何在動作中進行重定向?

感謝您清理這個!

到目前爲止,我的家庭控制器的樣子:

resources :home do 
    collection do 
     get 'about' 
     get 'contact' 
    end 
    end 

回答

1

你要找的變量是:

contact_home_index_url 

contact_home_index_path 

要找到這些(和看所有其他路由),請在命令行使用rake routes。在右邊,你會看到動作和控制器;找到你需要的行,取左邊的變量,並根據需要追加_path_url到最後。對於嵌套的路線,你需要提供一個參數,如:

new_event_boat_path(@event) 

至於從控制器重定向,嘗試:

def redirect_sample 
    redirect_to contact_home_index_url 
end 
+0

感謝,奇怪的是在這「索引」!即contact_home_index_path,我認爲這將是contact_home_path – Blankman 2010-12-07 03:49:35

相關問題