2013-06-30 30 views

回答

0
<%= link_to 'link_name', :action => 'Your_method_name', :controller => 'custom_hello' %> 

現在您需要在您的routes.rb中編寫'custome_hello/Your_method_name'並在該控制器中創建Your_method_name.html.erb頁面,當您點擊鏈接時,您將導航到Your_method_name.html.erb頁面嘗試它,這將起作用。

+0

我使用「匹配...」路線,但它只是顯示了我指定的動作,而不是進一步移動到我提供的鏈接。 –

2

這就是:

app/controllers/custom_hello_controller.rb

class CustomHelloController < ApplicationController 
    def method1 
    end 

    def method2 
    end 
end 

config/routes.rb

get 'custom_hello/method1' 
get 'custom_hello/method2' 

在視圖中創建兩個文件:

app/views/custom_hello/method1.html.erb 
app/views/custom_hello/method2.html.erb 

您可以CREA te鏈接:

<%= link_to 'Method 1', custom_hello_method1_path %> 
<%= link_to 'Method 2', custom_hello_method2_path %> 

但是,您可能會考慮創建REST控制器和路由。請閱讀here

相關問題