cómo evitar que los rieles muestren un mensaje flash dos veces

I am using bootstrap alert to style rails flash messages, but i don't know why it happens

 def render_flash_msgs
    unless @_flash_rendered
        @_flash_rendered = true
        render 'shared/flash_msgs'
    end
 end

  # return html class for flash_key
  def bootstrap_class_for(flash_key)
     flash_key == :notice ? 'alert-info' : "alert-#{flash_key}"
  end

I can't post image, so i can just post the html result sources

  <div id="flash">
  <div class="alert" title="Notice">
    <button class="close" data-dismiss="alert">×</button>
    <div>Post was successfully updated.</div>
  </div> 
  <!-- dont know why it showed again under the alert block -->
  <p id="notice">Post was successfully updated.</p>

Edit :-------------------------------------------------- here is my form

 = form_for @post do |f|
  - if @post.errors.any?
    #error_explanation
      h2 = "#{pluralize(@post.errors.count, "error")} prohibited this post from being saved:"
      ul
        - @post.errors.full_messages.each do |message|
          li = message

  .field
    = f.label :title
    = f.text_field :title
  .actions = f.submit 'Save'

here is my flash page -----------------------------------

#flash
  - flash.each do |type, message|
    .alert class=bootstrap_class_for(type)
      button.close data-dismiss="alert"
        | &times;
      div = message 

preguntado el 05 de mayo de 13 a las 07:05

Can you post the part of your .html.erb files where the flash message is displayed ? -

yeah, i already post _form and _flash partials -

1 Respuestas

Sounds like your alerts are displayed once in layout and once in form. Please show us layout and post _form parcial.

contestado el 05 de mayo de 13 a las 09:05

i just updated the question, but i dont have any rerendered alert in form page - user698855

Dónde está render_flash_msgs método llamado? - Alex Teut

called in application_helper - user698855

I see that you render flashes once in your form. And you have method render_flash_msgs which is called somewhere. I think that your application.html.slim has a string like = render_flash_msgs if flash.any?. So if you open your form, you see one set of flashes inside your form and another set in your layout. Hope you get my point. - Alex Teut

thank you so much, yeah, the notice flash got rendered again in _form - user698855

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.