Modify Devise alerts ( Rails 3)

走远了吗. 提交于 2019-12-25 02:33:03

问题


I am using devise in my rails app which comes with its own alert/flash helpers. I have modified it so that it looks like this

<% flash.each do |key, value| %>
<%= content_tag(:div, value, :class => "flash #{key}") %>
<% end %> 

What i want to do is to be able to close this alert with a X in the top corner, rather than refresh the page to make it disappear. I have created an alert box with css/jquery and surrounded the relevant divs around the above code, however as its in the layouts/application file it is always visible when the page loads

Here is the CSS and Jquery if it helps

$(function() {
$('.close').click(function(){
    $('.myDiv').fadeOut("fast");
});


.close {
background:red;
font-weight:bold;
padding:5px;
cursor:pointer;
display:inline-block;
 }

.myDiv {
padding:10px;
background:#ccc;
width: 200px;
margin:0 auto;
height:50px;
 }

回答1:


You can wrap the custom divs to only render if flash is not blank:

<% if flash.present? -%>
  <div id='flash'>
  ...
  </div>
<% end -%>


来源:https://stackoverflow.com/questions/10285948/modify-devise-alerts-rails-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!