Rails 3.1 Devise如何更改Flash Message CSS从通知到成功? [英] Rails 3.1 Devise How To Change Flash Message CSS From notice to success?

查看:77
本文介绍了Rails 3.1 Devise如何更改Flash Message CSS从通知到成功?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rails 3.1和Devise 1.5问题。

Rails 3.1 and Devise 1.5 question.

我正在使用以下代码在我的布局中显示Flash消息:

I'm using the following code to display flash messages in my layout:

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

我想将某些确认消息的CSS类从通知更改为成功,但是我不知道在哪里覆盖或更改密钥,因为我不知道它的设置位置。

I'd like to change the css class for some of my confirmation messages from notice to success, but I don't know where to override or change the key because I don't know where it's set.

有人能指出我正确的方向吗?

Can anybody point me in the right direction?

谢谢!

推荐答案

所以做到这一点的方法是编辑devise控制器

So the way to do this is to edit the devise controllers.

通过常规安装安装Devise时,我认为它不会安装控制器(至少不是我安装的)。

When you install Devise through the normal installation I don't think it install the controllers (at least it didn't for me).

因此,首先您应该手动添加控制器文件,并将其放入项目中的相同位置: https://github.com/plataformatec/devise/tree/master/app/controllers/devise

So first you should manually add the controller files and put them into your project in the same location: https://github.com/plataformatec/devise/tree/master/app/controllers/devise

一旦您的项目中有文件,请转到 sessions_controller.rb文件。

Once you have the files in your project, go to the "sessions_controller.rb" file.

一行16& 25,您应该看到以下代码:

One lines 16 & 25, you should see the code:

set_flash_message :notice, :signed_in

set_flash_message :notice, :signed_out

您只需要将:notice更改为:success

You just need to change ":notice" to ":success"

希望成功!

这篇关于Rails 3.1 Devise如何更改Flash Message CSS从通知到成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆