0.0
No commit activity in last 3 years
No release in over 3 years
simply_messages is a unified flash and error messages display solution
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.0.0
>= 0
>= 0

Runtime

>= 3.0.0
 Project Readme

simply_messages¶ ↑

simply_messages is a Rails plugin providing a unified notice/alert messages handling (like those: flash.now = ‘Yeah’) and model validation errors. Based on the message_block by Ben Hughes (github.com/railsgarden/message_block).

Requirements¶ ↑

Rails version 3.0+

Installation¶ ↑

Put this line in your Gemfile:

gem 'simply_messages'

Then bundle:

bundle

simply_messages uses standard I18n translations to display errors and as such requires at least the following keys to be present:

activerecord:
  errors:
    template:
      header:
        one: "1 error prohibited this %{model} from being saved"
        other: "%{count} errors prohibited this %{model} from being saved"

Usage¶ ↑

In ‘app/views/layouts/application.html.erb`:

<%= messages_block %>

By default the messages_block function will display all flash and flash messages and all errors for model object associated by name with the current controller (so it will display all model errors for @user model when ‘users’ is the current controller). It will also display appropriate messages for :success and :error flash keys.

We can also explicitly set the model we would like to display errors for, like this:

<%= messages_block :for => :comment %>

We can also display errors for more than one model:

<%= messages_block :for => [:post, :comment] %>

EXAMPLE 1¶ ↑

controller:

flash.now[:notice] = 'Post saved'

view:

<%= messages_block %>

will result in:

<div class="notice">
<p>Post saved</p>
</div>

EXAMPLE 2¶ ↑

Given a User model instance with one validation error:

user.errors
=> #<OrderedHash {:name=>["can't be blank"]}>

and this in the view in the users controller:

<%= messages_block %>

it will render:

<div class="alert">
<p>1 error prohibited this User from being saved:</p>
<ul>
<li>Name can't be blank</li>
</ul>
</div>

Contributing to simply_messages¶ ↑

  • Fork, fix, then send me a pull request.

Copyright © 2009-2011 Paweł Gościcki, released under the MIT license