Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ruby:2.3.1

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /app
WORKDIR /app

# Cache Dependency Install
ADD Gemfile /app/Gemfile
ADD Gemfile.lock /app/Gemfile.lock
RUN bundle install

# Add Repository
ADD . /app

# Run Server
EXPOSE 3000
CMD rake db:migrate && rails server -b 0.0.0.0
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
gem 'pg'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
Expand All @@ -15,7 +14,7 @@ gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Bulma CSS
gem 'haml'
gem "bulma-rails", "~> 0.2.3"
# Use jquery as the JavaScript library
gem 'jquery-rails'
Expand Down
9 changes: 6 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ GEM
ffi (1.9.14)
globalid (0.3.7)
activesupport (>= 4.1.0)
haml (4.0.7)
tilt
i18n (0.7.0)
jbuilder (2.6.0)
activesupport (>= 3.0.0, < 5.1)
Expand All @@ -82,6 +84,7 @@ GEM
nio4r (1.2.1)
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
pg (0.19.0)
puma (3.6.0)
rack (2.0.1)
rack-test (0.6.3)
Expand Down Expand Up @@ -132,7 +135,6 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.12)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.5)
Expand All @@ -159,19 +161,20 @@ DEPENDENCIES
bulma-rails (~> 0.2.3)
byebug
coffee-rails (~> 4.2)
haml
jbuilder (~> 2.5)
jquery-rails
listen (~> 3.0.5)
pg
puma (~> 3.0)
rails (~> 5.0.0, >= 5.0.0.1)
sass-rails (~> 5.0)
spring
spring-watcher-listen (~> 2.0.0)
sqlite3
turbolinks (~> 5)
tzinfo-data
uglifier (>= 1.3.0)
web-console

BUNDLED WITH
1.12.5
1.13.6
Binary file added app/assets/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/javascripts/todos.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,28 @@
*= require_tree .
*= require_self
*/
@import "bulma";

.hero {
margin-bottom: 30px;
}

.todo-list {
padding: 30px;
}

.addTodo {
margin-top: 30px;
}

.addTodo input {
width: 100%;
height: 50px;
padding: 10px;
resize: vertical;
font-size: 18px;
}

.addTodo label {
display: none;
}
34 changes: 34 additions & 0 deletions app/assets/stylesheets/scaffolds.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#notice {
color: red;
}

.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}

#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;

h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0;
background-color: #c00;
color: #fff;
}

ul li {
font-size: 12px;
list-style: square;
}
}
Empty file.
78 changes: 78 additions & 0 deletions app/controllers/todos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
class TodosController < ApplicationController
before_action :set_todo, only: [:show, :edit, :update, :destroy]

# GET /todos
# GET /todos.json
def index
@todos = Todo.all
@todo = Todo.new
end

# GET /todos/1
# GET /todos/1.json
def show
end

# GET /todos/new
def new
@todo = Todo.new
end

# GET /todos/1/edit
def edit
end

# POST /todos
# POST /todos.json
def create
@todo = Todo.new(todo_params)

respond_to do |format|
if @todo.content == ""
format.html { redirect_to todos_path, notice: 'Todo was blank!'}
format.json { render json: { error: 'Blank Todo!' }, status: :unprocessable_entity }
elsif @todo.save
format.html { redirect_to todos_path }
format.json { render :show, status: :created, location: @todo }
else
format.html { render todos_path }
format.json { render json: @todo.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /todos/1
# PATCH/PUT /todos/1.json
def update
respond_to do |format|
if @todo.update(todo_params)
format.html { redirect_to todos_path }
format.json { render :show, status: :ok, location: @todo }
else
format.html { render :edit }
format.json { render json: @todo.errors, status: :unprocessable_entity }
end
end
end

# DELETE /todos/1
# DELETE /todos/1.json
def destroy
@todo.destroy
respond_to do |format|
format.html { redirect_to todos_url, notice: 'Todo was successfully destroyed.' }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_todo
@todo = Todo.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def todo_params
params.require(:todo).permit(:content)
end
end
2 changes: 2 additions & 0 deletions app/helpers/todos_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module TodosHelper
end
2 changes: 2 additions & 0 deletions app/models/todo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Todo < ApplicationRecord
end
14 changes: 0 additions & 14 deletions app/views/layouts/application.html.erb

This file was deleted.

15 changes: 15 additions & 0 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
!!!
%html
%head
%title ToDo List
= favicon_link_tag "favicon.png", rel: 'shortcut icon', type: 'image/png'
= stylesheet_link_tag "application", media: "all"
= javascript_include_tag "application"
= csrf_meta_tags
%body
%section.hero.is-dark
.hero-body
.container
%h1.title Todo List
%h2.subtitle <em>Submit</em> a new Todo to get started!
= yield
16 changes: 16 additions & 0 deletions app/views/todos/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%= form_for(todo, :html => {:class => 'addTodo'}) do |f| %>
<% if todo.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(todo.errors.count, "error") %> prohibited this todo from being saved:</h2>

<ul>
<% todo.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<%= f.text_field :content, autofocus: true, placeholder: 'Add a Todo!' %>
<%= f.submit 'Submit', :class => 'button is-dark is-fullwidth' %>
<% end %>
2 changes: 2 additions & 0 deletions app/views/todos/_todo.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! todo, :id, :title, :description, :created_at, :updated_at
json.url todo_url(todo, format: :json)
6 changes: 6 additions & 0 deletions app/views/todos/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing Todo</h1>

<%= render 'form', todo: @todo %>

<%= link_to 'Show', @todo %> |
<%= link_to 'Back', todos_path %>
13 changes: 13 additions & 0 deletions app/views/todos/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.container.todo-list
- if @todos.empty?
%p There are no todos!
- else
- @todos.each do |todo|
%article.media
.media-content
.content
%p= todo.content
.media-right
%a= link_to 'Delete', todo, method: :delete, class: 'button is-danger'
=render 'form', todo: @todo
%p#notice= notice
1 change: 1 addition & 0 deletions app/views/todos/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @todos, partial: 'todos/todo', as: :todo
7 changes: 7 additions & 0 deletions app/views/todos/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.container
%p#notice= notice
%br
.box
%p= @todo.content
= link_to 'Edit', edit_todo_path(@todo), class: 'button'
= link_to 'Back', todos_path, class: 'button'
1 change: 1 addition & 0 deletions app/views/todos/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "todos/todo", todo: @todo
29 changes: 8 additions & 21 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
development: &default
adapter: postgresql
encoding: unicode
database: postgres
pool: 5
timeout: 5000
username: postgres
password:
host: db

development:
<<: *default
database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3

production:
<<: *default
database: db/production.sqlite3
database: myapp_test
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Rails.application.routes.draw do
root to: "todos#index"
resources :todos
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
11 changes: 0 additions & 11 deletions db/migrate/20161119011946_create_tasks.rb

This file was deleted.

8 changes: 8 additions & 0 deletions db/migrate/20161122050054_create_todos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateTodos < ActiveRecord::Migration[5.0]
def change
create_table :todos do |t|
t.string :content
t.timestamps
end
end
end
Loading