markdown Flash哈希

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Flash哈希相关的知识,希望对你有一定的参考价值。

## Flash Hash
* stores a message in the session data
* clears old message after every request
* Example: `flash[:notice] = "Hello!"`
* keys include: `:notice`, `:error`

```html 
<!--within a template file or layout file-->
<% if !flash[:notice].blank? %>
  <div class="notice"><%= flash[:notice] %></div>
<% end %>
```

* Create the flash message:

```ruby
# some controller:
  def create
    #...
    flash[:notice] = " HellOOO "
    redirect_to(:action => "" )
  end
  
  #OR
  
  def create
    #...
    redirect_to(), :notice => "HIIII"
  end
```

* You can pass anything from `alert`, `notice`, `flash`

## Displaying with different alert types
* In your `layouts/application.html.erb` file:

```ruby
<% flash.each do |name, msg| %>
  <div class="#{name}"><%= msg %></div>
<% end %>

#name could be alert, notice or flash 
#msg is the actual message
```

以上是关于markdown Flash哈希的主要内容,如果未能解决你的问题,请参考以下文章