简体   繁体   English

设计中禁用响应者gem flash消息

[英]Disable Responders gem flash message for devise sign in

We're running both devise and the responders gem in our project. 我们在项目中运行设计和响应者宝石。 We have removed the signed_in and signed_up flash messages as described here: Rails Disable devise flash messages 我们已经删除了signed_in和signed_up flash消息,如下所述: Rails禁用设计flash消息

Relevant part of config/locales/devise.en.yml: config / locales / devise.en.yml的相关部分:

devise:
  sessions:
    signed_in: ''
    signed_out: ''

But now upon sign in the flash we receive is "User was successfully created." 但是现在我们收到的消息是“用户已成功创建”。 We've traced this down to the responders gem. 我们已将此追溯到响应者宝石。 Here's our config/locales/responders.en.yml file: 这是我们的config / locales / responders.en.yml文件:

en:
  flash:
    actions:
      create:
        notice: '%{resource_name} was successfully created.'
      update:
        notice: '%{resource_name} was successfully updated.'
      destroy:
        notice: '%{resource_name} was successfully destroyed.'
        alert: '%{resource_name} could not be destroyed.'

I get why it would be saying User was created (the devise session was created, with a resource of user) but everything I've tried so far doesn't remove that message (short of removing the entire responders gem). 我明白为什么会说用户是创建的(设计会话是用用户的资源创建的),但到目前为止我尝试的所有内容都没有删除该消息(除了删除整个响应者宝石)。

I've tried adding a few specific entries with an empty message to the responders.en.yml file: 我已经尝试将一些带有空消息的特定条目添加到responders.en.yml文件中:

en:
  flash:
    actions:
      create:
        notice: '%{resource_name} was successfully created.'
      update:
        notice: '%{resource_name} was successfully updated.'
      destroy:
        notice: '%{resource_name} was successfully destroyed.'
        alert: '%{resource_name} could not be destroyed.'
    users:
      create:
        notice: ''
        success: ''
    sessions:
      create:
        notice: ''
        success: ''

but we're still getting the same "User was successfully created." 但我们仍然得到相同的“用户已成功创建。” flash message upon sign in. 登录后闪烁消息。

Rails: 4.0.4 Devise: 3.2.2 Responders: 1.0.0 Rails:4.0.4设计:3.2.2响应者:1.0.0

How can I disable this flash message when a user signs in and a session is created? 如何在用户登录并创建会话时禁用此Flash消息?

I just came across this myself and thought I should come back with a bit of an answer on this. 我自己也遇到了这个问题,我想我应该回答一下这个问题。 You were really close on your attempt, but had the nesting slightly wrong. 你真的很接近你的尝试,但嵌套有点错误。

en:
  flash:
    actions:
      create:
        notice: '%{resource_name} was successfully created.'
        alert: '%{resource_name} could not be created.'

      ...your other responders here...

    devise:
      sessions:
        create:
          notice: ''

The only real difference from your question is that sessions is nested under devise . 与您的问题唯一真正的区别是sessions嵌套在devise之下。

Good luck! 祝好运!

Just to add to Jay's answer. 只是为了补充周杰伦的答案。 If you are overriding Devise's SessionsController, you must remove the devise key in the locale file. 如果要覆盖Devise的SessionsController,则必须删除语言环境文件中的设计密钥。 So it will be: 所以它将是:

en:
  flash:
    actions:
      create:
        notice: '%{resource_name} was successfully created.'
        alert: '%{resource_name} could not be created.'
        ...your other responders here...

    sessions:
      create:
        notice: ''

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM