ruby - Show error message in Flash alert Rails 3 -


if set validation message within model

validates :name, :presence => {:message => 'the name cant blank.'} 

how message show in flash alert, have tried far

def create    @message = message.new(params[:message])    if @message.valid?      contactmailer.send_mail(@message).deliver      redirect_to(root_path, :notice => "thanks message, in touch soon")    else      flash[:error] = @message.errors      render :new    end end 

but black error message strip @ top of page no text in it, in layout/application have this

<% flash.each |name, msg| %> <div class="alert alert-<%= name == :notice ? "success" : "error" %>">   <%= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(string) %> </div> 

any pointers appreciated

this not idea show validation errors through flash message, if need it:

flash.now[:error] = @message.errors[:name].first 

you should use flash.now[:error] in case if need show message immediately.

http://api.rubyonrails.org/classes/actiondispatch/flash/flashhash.html#method-i-now http://api.rubyonrails.org/classes/activemodel/errors.html#method-i-5b-5d


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -