【问题标题】:How to add more than one flash[:notice] at a interactive mode?如何在交互模式下添加多个 flash[:notice]?
【发布时间】:2018-01-16 12:06:06
【问题描述】:

我正在使用unobtrusive_flash,我的视图仅显示最新的快闪通知。如何显示所有闪光通知?另外,是否可以在应用程序运行时以交互方式显示 flash-notice?

我完全可以接受任何解决方案,即使它不使用unobtrusive_flash

查看

<div class="unobtrusive-flash-container"></div>

控制器

-------
while do
  begin
    config = {
      consumer_key:        '******',
      consumer_secret:     '*******',
      access_token:    '********',
      access_token_secret: '********'
    }
    rClient = Twitter::REST::Client.new config
    sClient = Twitter::Streaming::Client.new(config)
    topics = ['#trump', '#rails']
    sClient.filter(:track => topics.join(',')) do |tweet|
      if tweet.is_a?(Twitter::Tweet)
        puts tweet.text
        flash[:notice] = [tweet.text]
        flash[:notice] << tweet.text
        rClient.retweet tweet
      end
    end
  rescue
    puts 'error occurred, waiting for 5 seconds'
    flash[:error] = ['error occurred, waiting for 5 seconds']
    flash[:error] << 'error occurred, waiting for 5 seconds'
  end

【问题讨论】:

  • “在应用程序运行时以交互方式显示 flash-notices”是什么意思?

标签: ruby-on-rails ruby actionview


【解决方案1】:
flash[:notice] = [tweet.text]
flash[:notice] << tweet.text

应该是

flash[:notice] ||= [] # initialize a new array, the first time only
flash[:notice] << tweet.text

否则你每次都会重新初始化闪存阵列

但老实说,我认为你应该看看:http://edgeguides.rubyonrails.org/action_cable_overview.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 2021-05-14
    • 1970-01-01
    • 2011-02-11
    • 2011-01-01
    • 2013-06-27
    • 2017-02-11
    相关资源
    最近更新 更多