This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'bundler/setup' | |
| Bundler.require(:default) | |
| require_relative 'lib/todo' | |
| require_relative 'app/controllers/tasks_controller' | |
| require_relative 'app/models/task' | |
| use Rack::Static, root: 'public', urls: ['/images', '/js', '/css'] | |
| use Rack::ContentLength |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require_relative 'todo/application' | |
| require_relative 'todo/base_controller' | |
| require_relative 'todo/router' | |
| module Todo | |
| autoload :Application, 'todo/application' | |
| autoload :BaseController, 'todo/base_controller' | |
| autoload :Router, 'todo/router' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Todo | |
| class Application | |
| class << self | |
| attr_accessor :env | |
| def call(env) | |
| self.env = env | |
| Rack::Response.new( *dispatch) | |
| # if(env['PATH_INFO'] == '/') | |
| # Rack::Response.new(TasksController.new.index) | |
| # end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Todo | |
| class Router | |
| attr_reader :app | |
| ROUTES = { | |
| '/' => {'controller' => 'tasks', 'action' => 'index'}, | |
| '/save_task' => {'controller' => 'tasks', 'action' => 'save'}, | |
| '/edit' => {'controller' => 'tasks', 'action' => 'edit'}, | |
| '/update' => {'controller' => 'tasks', 'action' => 'update'}, | |
| '/delete' => {'controller' => 'tasks', 'action' => 'destroy'} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TasksController < Todo::BaseController | |
| def index | |
| @tasks = Task.all | |
| render("tasks/index") | |
| end | |
| def edit | |
| @task = Task.where(params["id"]) | |
| render("tasks/edit") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Todo | |
| class BaseController | |
| attr_reader :env | |
| def initialize(env) | |
| @env = env | |
| end | |
| def params | |
| Rack::Request.new(env).params |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Task | |
| DB = PG.connect :hostaddr => "127.0.0.1", :port => 5432, :dbname => 'testdb', :user => "postgres", :password => "postgres" | |
| #uncomment while deploying to heroku | |
| #DB = PG.connect ENV["HEROKU_POSTGRESQL_SILVER_URL"] | |
| # uncomment to create pg database | |
| # DB = PG.connect(hostaddr: "127.0.0.1", port: 5432, dbname: 'postgres', user: 'postgres', password: "postgres") | |
| # DB.exec("CREATE DATABASE testdb") | |
| # uncomment to create table | |
| # DB.exec "DROP TABLE IF EXISTS tasks" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source 'https://rubygems.org' | |
| gem 'activerecord', '~> 5.0', '>= 5.0.0.1' | |
| gem 'pg' | |
| gem 'sinatra' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'active_record' | |
| require 'pg' | |
| require 'sinatra' | |
| ActiveRecord::Base.establish_connection( | |
| adapter: 'postgresql', | |
| host: 'localhost', | |
| username: 'postgres', | |
| password: 'postgres', | |
| database: 'testdb' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head><title>Todo</title></head> | |
| <link rel="stylesheet" href="/css/style.css"> | |
| <body> | |
| <%= yield %> | |
| <script src="/js/main.js"></script> | |
| </body> | |
| </html> |