Skip to content

Instantly share code, notes, and snippets.

@mgiagante mgiagante/app.rb
Created Mar 26, 2018

Embed
What would you like to do?
require "cuba"
require "mote"
require "mote/render"
Cuba.plugin Mote::Render
require_relative "controllers/pages"
require_relative "controllers/tasks"
require_relative "db/data_store"
require_relative "models/task"
DataStore.load_data
Cuba.define do
on get do
on "dashboard" do
with action: :dashboard do
run PagesController
end
end
end
on root do
res.redirect "dashboard"
end
on post do
on "tasks/:id" do |id|
on param(:event) do |event|
with action: :trigger, id: id.to_i, event: event do
run TasksController
end
end
end
end
end
class TasksController < Cuba
define do
on default do
res.write public_send(*vars.values)
res.redirect "/dashboard"
end
end
def trigger(id, event)
target_task = DataStore::Tasks.all.find { |task| task.id == id }
target_task.public_send(event)
target_task.status
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.