我正在使用unobtrusive_flash
,我的视图仅显示最新的Flash通知。如何显示所有闪光灯通知?此外,是否可以在应用程序运行时以交互方式显示闪存通知?
即使不使用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
答案 0 :(得分:0)
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