2011-04-10 52 views
0

我有休耕代碼:輸出傳遞值

<%= link_to 'Get started now !',play_path ,:alert => 'Eroare bla bla bla',:notice => 'E ok' %> 

我怎麼能在HTML輸出的「play_path頁面上:警報值?

我的控制器看起來像這樣

def index 
    @alert = flash[:alert] 
    @notice = flash[:notice] 

    end 

在我看來,我有

<%[email protected] %> 

它只是不顯示任何內容,但如果在我的控制器我修改@alert = :blablabla,它顯示在我的查看「blablabla」

回答

1

您的鏈接:

<%= link_to 'Get started now !',play_redirect_path ,:alert => 'Eroare bla bla bla',:notice => 'E ok' %> 

在你的控制器

def redirect 
    redirect_to play_path, :alert => params[:alert] 
end 

def show 
    @alert = flash[:alert] 
end 

在你看來

<%= @alert %> 

您還需要建立一個路徑在你的配置routes.rb中

match "play/redirect" => "plays#redirect" 
+0

我已經加了我控制器索引def @alert = flash [:alert] @notice = flash [:notice],當我使用下面的代碼時:<%[email protected] %>它不會執行任何操作。如果我在我的控制器@alert =:blablabla中執行此操作,將顯示文本blablabla: - ?? – Alex 2011-04-10 13:41:58

+0

啊,他們是閃光消息......看我的編輯。 – Gazler 2011-04-10 13:47:03

+0

爲什麼我不能在控制器中執行@alert = flash [:alert]? (它似乎不工作) – Alex 2011-04-10 14:32:41