Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I usually just use flash[:notice] for notification messages such as "Your account was updated successfully" and either flash[:error] or <code>error_msg_for</code> for error messages. I use error_msg_for errors caused by validation failure and flash[:error] for all other kinds of error messages. Unless absolutely necessary I take care not to set them both on the same action. </p> <p>I also try to avoid returning a use to a form they just submitted if their action succeeded. I think it's sending contradictory signals to post a success message and send the user back to the form they just submitted. My rule of thumb is "redirect on success, render on failure." For example, I will <code>redirect to @user</code> if @user is saved on an update, but will render :edit if the save is unsuccessful.</p> <p>Sample controller code.</p> <pre><code>before_filter :identify_user, :except =&gt; :index def update @user = User.find(params[:id]) if @user.update_attributes(params) flash[:notice] = "Your account was updated successfully" redirect_to @user else render :action =&gt; :edit end end def index end def identify_user begin @user = User.find(params[:id]) rescue flash[:error] = "You specified an unknown user" redirect users_path end end </code></pre> <p>My notification partial called in my application layout.</p> <pre><code>&lt;div id="notification_area"&gt; &lt;% flash.each do |key, value| %&gt; &lt;% if value %&gt; &lt;div id="&lt;%=key%&gt;"&gt; &lt;%= value %&gt; &lt;/div&gt; &lt;%end%&gt; &lt;%end%&gt; &lt;/div&gt; </code></pre>
 

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