I've done a little system that logs the tasks. The user logs on and registers a title with a description and a date of type datetime in the database. In the system it can view your tasks, delete and edit.
I would like to add a timer type that starts counting from the date and time set in the job creation, ie a timer that shows the time the specific job is consuming.
I installed the gem rails timeago and in one of my views I gave the command:
<% = Timeago_tag Time.zone.now,: nojs => true,: limit => 10.days.ago%>
With this I was able to show a timer on the screen that counts the time the page was loaded, but I would like to show the time the task is consuming.
I'm putting my schematic code and my controller:
Schema:
ActiveRecord::Schema.define(version: 20170412011539) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "tarefas", force: :cascade do |t|
t.string "titulo"
t.text "descricao"
t.datetime "data"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.index ["user_id"], name: "index_tarefas_on_user_id", using: :btree
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_users_on_email", unique: true, using: :btree
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end
add_foreign_key "tarefas", "users"
end
Task controller:
class TarefasController < ApplicationController
before_filter :authenticate_user!
def index
@tarefa = current_user.tarefas.all
end
def show
@tarefa = Tarefa.find(params[:id])
end
def new
@tarefa = Tarefa.new
end
def edit
@tarefa = current_user.tarefas.find_by(id: params[:id])
end
def create
@tarefa = current_user.tarefas.new(tarefa_params)
if @tarefa.save
redirect_to @tarefa
else
render 'new'
end
end
def update
@tarefa = current_user.tarefas.find_by(id: params[:id])
if @tarefa.update(tarefa_params)
redirect_to @tarefa
else
render 'edit'
end
end
def destroy
@tarefa = current_user.tarefas.find_by(id: params[:id])
@tarefa.destroy
redirect_to tarefas_path
end
private
def tarefa_params
params.require(:tarefa).permit(:titulo, :descricao, :data)
end
end