如何在交互模式下添加多个 flash[:notice]?
How to add more than one flash[:notice] at a interactive mode?
我正在使用 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
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
我正在使用 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
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