diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000..84f5661 Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/assets/images/logo.png b/app/assets/images/logo.png new file mode 100644 index 0000000..965f1a5 Binary files /dev/null and b/app/assets/images/logo.png differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e07c5a8..8233b43 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,4 +13,3 @@ //= require jquery //= require jquery_ujs //= require turbolinks -//= require_tree . diff --git a/app/assets/javascripts/login_signup.js b/app/assets/javascripts/login_signup.js new file mode 100644 index 0000000..12f3a8d --- /dev/null +++ b/app/assets/javascripts/login_signup.js @@ -0,0 +1,7 @@ +$(function () { + $('img').hover(function () { + $(this).addClass('dancing'); + }, function () { + $(this).removeClass('dancing'); + }); +}); diff --git a/app/assets/javascripts/transgressions.coffee b/app/assets/javascripts/transgressions.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/transgressions.coffee @@ -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/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 125c24e..44e64e4 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -14,6 +14,14 @@ *= require_self */ +* { + box-sizing: border-box; +} + +html { + font-size: 24px; +} + div.alert { background: pink; border: 1px solid black; @@ -21,3 +29,48 @@ div.alert { padding: 1rem; font-size: 1.4rem; } + +header { + height: 4rem; + + border-bottom: 2px solid grey; +} + +header { + background: #222; + color: deeppink; + padding: 0.5rem; +} + +.logo > img { + display: block; + float: left; + height: 3rem; + padding: 0.5rem; + + transition: 0.5s transform bounce; +} + +.logo > img.dancing { + transform: scaleX(-1); +} + +span { + font-family: cursive; + display: block; + float: left; + font-size: 2.6rem; + line-height: 3rem; +} + +nav { + float: right; + color: white; +} + +nav a { + color: white; + text-decoration: none; + font-size: 1.3rem; + line-height: 3rem; +} diff --git a/app/assets/stylesheets/transgressions.scss b/app/assets/stylesheets/transgressions.scss new file mode 100644 index 0000000..c1b1bd4 --- /dev/null +++ b/app/assets/stylesheets/transgressions.scss @@ -0,0 +1,10 @@ +// Place all the styles related to the transgressions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +form input, form select { + padding: 0.5rem; + font-size: 2rem; + border: 1px solid green; + width: 75%; +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9617794..ecabe61 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -24,4 +24,12 @@ class ApplicationController < ActionController::Base @current_user = false end end + + def logged_in? + !!current_user + end + + def require_current_user + redirect_to root_path unless logged_in? + end end diff --git a/app/controllers/transgressions_controller.rb b/app/controllers/transgressions_controller.rb new file mode 100644 index 0000000..5f7b2ad --- /dev/null +++ b/app/controllers/transgressions_controller.rb @@ -0,0 +1,43 @@ +class TransgressionsController < ApplicationController + before_action :require_current_user + + def new + @transgression = Transgression.new + end + + def create + @transgression = current_user.transgressions + .new(transgression_params) + + if @transgression.save + redirect_to transgressions_path + else + flash[:message] = @transgression.errors.full_messages.to_sentence + render :new + end + end + + def edit + end + + def update + # params[:id] + end + + def show + end + + def index + @transgressions = current_user.transgressions + end + + def delete + end + + private + + def transgression_params + return params.require(:transgression) + .permit(:sin_type, :description) + end +end diff --git a/app/helpers/transgressions_helper.rb b/app/helpers/transgressions_helper.rb new file mode 100644 index 0000000..341e0fd --- /dev/null +++ b/app/helpers/transgressions_helper.rb @@ -0,0 +1,2 @@ +module TransgressionsHelper +end diff --git a/app/models/transgression.rb b/app/models/transgression.rb new file mode 100644 index 0000000..7f4c475 --- /dev/null +++ b/app/models/transgression.rb @@ -0,0 +1,14 @@ +class Transgression < ActiveRecord::Base + SIN_TYPES = [ + 'Gluttony', 'Greed', 'Anger', 'Pride', + 'Lust', 'Sloth', 'Envy' + ] + + validates :description, presence: true + validates :user, presence: true + validates :sin_type, inclusion: { in: SIN_TYPES } + + belongs_to :user +end + +# Transgression::SIN_TYPES diff --git a/app/models/user.rb b/app/models/user.rb index b6922d9..8e0dc61 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,4 +7,6 @@ class User < ActiveRecord::Base validates :password, length: { minimum: 8, allow_nil: true } + + has_many :transgressions end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb new file mode 100644 index 0000000..50fcd76 --- /dev/null +++ b/app/views/layouts/_header.html.erb @@ -0,0 +1,17 @@ +
+ + +
+ +<%= javascript_include_tag 'login_signup.js' %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 46ecdfa..340ec71 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,6 +7,8 @@ <%= csrf_meta_tags %> + <%= render partial: 'layouts/header' %> + <% if flash[:message] %>
<%= flash[:message] %> diff --git a/app/views/transgressions/index.html.erb b/app/views/transgressions/index.html.erb new file mode 100644 index 0000000..f2add68 --- /dev/null +++ b/app/views/transgressions/index.html.erb @@ -0,0 +1,3 @@ +<% @transgressions.each do |trans| %> +
For the sin of <%= trans.sin_type %>: <%= trans.description %>
+<% end %> diff --git a/app/views/transgressions/new.html.erb b/app/views/transgressions/new.html.erb new file mode 100644 index 0000000..be7b5af --- /dev/null +++ b/app/views/transgressions/new.html.erb @@ -0,0 +1,17 @@ +
+ +
+ + +
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 01ef3e6..88c82b0 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -8,4 +8,4 @@ Rails.application.config.assets.version = '1.0' # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. -# Rails.application.config.assets.precompile += %w( search.js ) +Rails.application.config.assets.precompile += %w( login_signup.js ) diff --git a/config/routes.rb b/config/routes.rb index 6e9f819..b1b3cd6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :transgressions root 'application#welcome' get '/amiloggedin' => 'application#amiloggedin' diff --git a/db/migrate/20151029180427_create_transgressions.rb b/db/migrate/20151029180427_create_transgressions.rb new file mode 100644 index 0000000..723b7d2 --- /dev/null +++ b/db/migrate/20151029180427_create_transgressions.rb @@ -0,0 +1,13 @@ +class CreateTransgressions < ActiveRecord::Migration + def change + create_table :transgressions do |t| + t.references :user, index: true, foreign_key: true + t.string :description, null: false + t.string :sin_type, null: false + + t.timestamps null: false + end + + add_index :transgressions, :sin_type + end +end diff --git a/db/schema.rb b/db/schema.rb index af18b97..0f3821c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,11 +11,22 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151029150245) do +ActiveRecord::Schema.define(version: 20151029180427) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "transgressions", force: :cascade do |t| + t.integer "user_id" + t.string "description", null: false + t.string "sin_type", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "transgressions", ["sin_type"], name: "index_transgressions_on_sin_type", using: :btree + add_index "transgressions", ["user_id"], name: "index_transgressions_on_user_id", using: :btree + create_table "users", force: :cascade do |t| t.string "email", null: false t.string "password_digest", null: false @@ -25,4 +36,5 @@ ActiveRecord::Schema.define(version: 20151029150245) do add_index "users", ["email"], name: "index_users_on_email", using: :btree + add_foreign_key "transgressions", "users" end diff --git a/test/controllers/transgressions_controller_test.rb b/test/controllers/transgressions_controller_test.rb new file mode 100644 index 0000000..ab924b9 --- /dev/null +++ b/test/controllers/transgressions_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class TransgressionsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/transgressions.yml b/test/fixtures/transgressions.yml new file mode 100644 index 0000000..8be4b71 --- /dev/null +++ b/test/fixtures/transgressions.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + user_id: + description: MyString + sin_type: MyString + +two: + user_id: + description: MyString + sin_type: MyString diff --git a/test/models/transgression_test.rb b/test/models/transgression_test.rb new file mode 100644 index 0000000..321318d --- /dev/null +++ b/test/models/transgression_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class TransgressionTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end