I'm creating my first sample Rails application. I have used rufus-scheduler in my application and call controller's action after every 10 sec. My code as follows:
我正在创建我的第一个示例Rails应用程序。我在我的应用程序中使用了rufus-scheduler,并在每10秒后调用控制器的动作。我的代码如下:
In config/initializers I've created task_scheduler.rb and it contains:
在config / initializers中我创建了task_scheduler.rb,它包含:
require 'rubygems'
require 'rufus/scheduler'
scheduler = Rufus::Scheduler.new
scheduler.every("10s") do
MyTaskController.doSomething
end
I also created a controller named MyTaskController and code is:
我还创建了一个名为MyTaskController的控制器,代码是:
class MyTaskController < ApplicationController
def self.doSomething
puts "some task"
end
end
It works perfectly, but I want to show a popup alert instead of using puts function. Is it possible in rails to call a javascript alert or javascript:window.open from controller (my doSomething action)?
它工作得很好,但我想显示一个弹出警报,而不是使用puts函数。是否可以在rails中从控制器调用javascript警报或javascript:window.open(我的doSomething操作)?
2 个解决方案
#1
0
You can render a view which has javascript code in it that contains javascript alert or javascript:window.open
您可以渲染一个包含javascript代码的视图,其中包含javascript alert或javascript:window.open
Similar question was brought up: Rails 3: How to send Javascript code from Controller?
提出了类似的问题:Rails 3:如何从Controller发送Javascript代码?
#2
-1
All you need is some JavaScript library such as jQuery, Lightbox, etc. to do that
所有你需要的是一些JavaScript库,如jQuery,Lightbox等
#1
0
You can render a view which has javascript code in it that contains javascript alert or javascript:window.open
您可以渲染一个包含javascript代码的视图,其中包含javascript alert或javascript:window.open
Similar question was brought up: Rails 3: How to send Javascript code from Controller?
提出了类似的问题:Rails 3:如何从Controller发送Javascript代码?
#2
-1
All you need is some JavaScript library such as jQuery, Lightbox, etc. to do that
所有你需要的是一些JavaScript库,如jQuery,Lightbox等