2010-03-24 50 views
6

我敢肯定,這是很容易,一旦你知道的軌道,但我是新來的吧...使用提交按鈕鏈接到另一個頁面中軌後

我想重定向到另一頁/行動提交按鈕(f.submit)被按下,並且只有在按下之後。在按下提交按鈕後,你如何確定你去的鏈接?

回答

6

提交按鈕用於將表單提交給控制器操作。在控制器操作中,您可以使用redirect_to方法重定向到另一個頁面。

例如,假設您有創建窗口小部件的窗體。該表單通常會提交到WidgetsController中的create操作,該操作可能會重定向到包含新創建的小部件的小部件列表:

class WidgetsController < ApplicationController 
    ... 
    def create 
    # Do stuff to create the Widget 
    ... 
    redirect_to widgets_path # Redirects to /widgets 
    end 
end 
class WidgetsController < ApplicationController 
    ... 
    def create 
    # Do stuff to create the Widget 
    ... 
    redirect_to widgets_path # Redirects to /widgets 
    end 
end 
相關問題