[英]How to add more than one flash[:notice] at a interactive mode?
我正在使用unobtrusive_flash
,但我的視圖僅顯示最新的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
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.