Hello. I'm trying to use modals for the output of :notices or :errors.
In the application.html.erb I use: <% flash.each do |name, msg| %> <% if msg.is_a?(String) %> <div id="modal1" class="modal"> <div class="modal-content"> <p><%= msg %></p> </div> <div class="modal-footer"> <a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat">Close</a> </div> </div> <% end %> <% end %> In my application.js file I use: var ready; ready = function() { var modal1 = document.getElementById('#modal1'); if (modal1.length > 0) { $('#modal1').openModal(); } }; $(document).ready(ready); $(document).on('page:load', ready); I tried checking if the string is not null too, but this won't change a thing. Only if I use: var ready; ready = function() { $('#modal1').openModal(); } $(document).ready(ready); $(document).on('page:load', ready); it works, but then it is shown everytime a page is reloaded an I don't want this behaviour. Why do those checks not work? Any help would be appreciated. Kind regards. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2de3b801-4f46-424e-b0f4-04591bc076e2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.