flash
本質上是基於散列。每種類型的Flash消息都只是與該類型的符號鍵關聯的值。因此,flash[:error]
用於錯誤消息,flash[:notice]
和flash[:success]
用於其關鍵類型。你甚至可以定義你自己的類型(只使用任何符號)。並且您可以一次設置任意數量的鍵(例如,您可以在同一請求中設置flash[:notice]
和flash[:error]
)。
在你的例子中,這是創建一個div
與類alert-message #{key}
。因此,舉例來說,如果你設置一個flash[:notice]
輸出將是:
<div class="alert-message notice">Notice message</div>
它會打印出一個給你設定每種類型。因此,如果請求中設置flash[:error] = 'something went terribly wrong'
和flash[:notice] = 'take a look around'
,你會從該模板得到這個網站:
<div class="alert-message error">something went terribly wrong</div>
<div class="alert-message notice">take a look around</div>
看起來你已經是,與CSS類? – sevenseacat