flash[:notice] / flash[:error], again

So, I’ve ended up changing my code to:

if @user.update_attributes(params[:user])
  flash[:notice] = "Profile updated"
  redirect_to :action => 'edit'
else
  flash.now[:error] = @user.errors.full_messages.first
  render :action => 'edit'
end

Basically, using a redirect_to on the else means you loose your post values when an error is encountered, so changing to render works nicely and using flash.now means those flash notices don’t linger after subsequent clicks. See this page for more info.

Leave a Reply

You must be logged in to post a comment.