Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Below solution works with latest devise as of now (4.1.1) and Rails 4.2.6. But is so simple that I don't see the reason why wouldn't it work 10 years from now;)</p> <p>If you want to recycle your error messages and have them look the same across your app I would recommend something like this (way I have learned with Michael Hartl tut):</p> <p>Create partial for error messages: <code>layouts/_error_messages.html.erb</code> Put inside following code (here I use some bootstrap 3 classes):</p> <pre><code>&lt;% if object.errors.any? %&gt; &lt;div id="error_explanation"&gt; &lt;div class="alert alert-danger alert-dismissable"&gt; &lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;&amp;times;&lt;/button&gt; &lt;p&gt;&lt;strong&gt;This form contains &lt;%= pluralize(object.errors.count, 'error') %&gt;.&lt;/strong&gt;&lt;/p&gt; &lt;ul&gt; &lt;% object.errors.full_messages.each do |msg| %&gt; &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>Now you have something recyclable and you can use it across the board. Instead of standard devise: </p> <pre><code>&lt;%= devise_error_messages! %&gt; </code></pre> <p>Call it in your form like this:</p> <pre><code>&lt;%= render 'layouts/error_messages', object: resource %&gt; </code></pre> <p>You can put it in any form. Instead of passing devise resource you can pass variable from your form like this:</p> <pre><code>&lt;%= form_for @post do |f| %&gt; &lt;%= render 'layouts/error_messages', object: f.object %&gt; &lt;%= f.text_field :content %&gt; &lt;%= f.submit %&gt; &lt;% end %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload