haml snippets

How to display Flash messages in Rails

Tagged flash, rails, erb, haml  Languages ruby

Place the following in your ERB view:

<% [:info, :error].each do |key| %>
  <% if flash[key] %>
  <div class="<%= key %>" id="flash">
    <%= flash[key] %>
  </div>
  <% end %>
<% end %>

or use the following if you prefer Haml:

- [:notice, :error, :success].each do |key|
  - unless flash[key].blank?
    %p{ :class => "flash #{key}" }= flash[key]

How to generate HAML views for Devise

Tagged devise, haml, rails3  Languages ruby

This will generate HAML views with Rails 3, HAML >=3.0.18 (won't work with lower version), and the latest devise version:

$ rails generate devise:views -e haml

If you see the following error when running the command:

Required dependency ruby_parser not found!
    Run "gem install ruby_parser" to get it.
Required dependency hpricot not found!
    Run "gem install hpricot" to get it.

make sure you have the following dependencies in Gemfile:

group :development do
  gem 'hpricot'
  gem 'ruby_parser'
end