⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 task_controller.rb

📁 RubyonRailsC.zip ruby on rails的源码
💻 RB
字号:
class TaskController < ApplicationController
	before_filter :set_charset 
	
	def set_charset 
		@headers["Content-Type"] = "text/html; charset=GB2312" 
	end 
	
	def index
		@editable = true
		@current_task = Task.find(:first, :conditions => ['isdone =?', 1])
		@editable = false if @current_task
		@success = Task.count(['isdone =?', 2])
		@failures = Task.count(['isdone =?', 3])
		@history = []

		ary = Task.find(:all, :conditions => ['not isdone =?', 1]).reverse
		if ary.size >= 8
			ary[0..7].each {|ar|
				x = TaskHelper::time_convert(Time.now.to_i - ar.finished)
				@history << {'state' => ar.state.value, 'body' => ar.body, 'time' => x }
			}
		else
			ary.each {|ar|
				x = TaskHelper::time_convert(Time.now.to_i - ar.finished)
				@history << {'state' => ar.state.value, 'body' => ar.body, 'time' => x }
			}
			(8 - ary.size).times { @history << {'state' => ' ', 'body' => ' ', 'time' => ' ' } }
		end
	end

	def create
		task = Task.new(params[:task])
		task.uid = 1
		task.created_at = params[:task][:created_at]
		task.body = params[:task][:created_at] + ' ' + params[:task][:body]
		task.finished = 0
		task.save

		redirect_to :action => 'index'
	end

	def eval
		task = Task.find(params[:task][:id])
		task.finished = Time.now.to_i
		params.each {|key, value|
			case key
			when 'action=done'
				task.isdone = 2
			when 'action=failed'
				task.isdone = 3
			end
		}
		task.save

		redirect_to :action => 'index'
	end

	def clear
		Task.destroy_all(['uid =?', 1])
		redirect_to :action => 'index'
	end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -