안녕하세요 저는 루비에서 몇 일간의 경험과 레일에서 아주 초보자입니다. 스레드를 사용하여 스톱워치 프로그램을 만들었습니다. 하지만 이제는 내 Rails 앱에 넣고보기에는 이벤트를 추적하고있는 스톱워치를 시작, 중지, 재개하는 버튼이 있어야합니다. 누군가가 루비 프로그램을 레일에 끼워 넣고 볼 수 있습니까? 아래 프로그램은보기에서 시작/정지/다시 시작 버튼에서 호출해야rails3에 사용자 생성 루비 프로그램을 포함시키는 법
stopwatch.rb : (그것은 단지이 방법을 시작하고 현재로서는 방법을 일시 중지)
class Stopwatch
def initialize
@t_start
@t_elapsed
@t_total
@t_current
end
def start
@t_start = Time.now
t = Thread.new do
while true do
@t_current = Time.now
puts @t_current
@t_elapsed = @t_current - @t_start
puts "Time elapsed is : #{@t_elapsed.to_i} seconds"
sleep 1
end
end
end
def pause
# Stop the Thread => Sleep the Thread until Resume is pressed.
t.kill
# Calculate the elapsed time
@t_elapsed = @t_current - @t_start
end
end
ticker = Stopwatch.new
ticker.start
고마워,