master
Matthew F. Short 10 years ago
parent 002574f559
commit 5a74813ce4

BIN
app/.DS_Store vendored

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 KiB

@ -13,4 +13,3 @@
//= require jquery //= require jquery
//= require jquery_ujs //= require jquery_ujs
//= require turbolinks //= require turbolinks
//= require_tree .

@ -0,0 +1,7 @@
$(function () {
$('img').hover(function () {
$(this).addClass('dancing');
}, function () {
$(this).removeClass('dancing');
});
});

@ -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/

@ -14,6 +14,14 @@
*= require_self *= require_self
*/ */
* {
box-sizing: border-box;
}
html {
font-size: 24px;
}
div.alert { div.alert {
background: pink; background: pink;
border: 1px solid black; border: 1px solid black;
@ -21,3 +29,48 @@ div.alert {
padding: 1rem; padding: 1rem;
font-size: 1.4rem; 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;
}

@ -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%;
}

@ -24,4 +24,12 @@ class ApplicationController < ActionController::Base
@current_user = false @current_user = false
end end
end end
def logged_in?
!!current_user
end
def require_current_user
redirect_to root_path unless logged_in?
end
end end

@ -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

@ -0,0 +1,2 @@
module TransgressionsHelper
end

@ -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

@ -7,4 +7,6 @@ class User < ActiveRecord::Base
validates :password, length: { validates :password, length: {
minimum: 8, allow_nil: true minimum: 8, allow_nil: true
} }
has_many :transgressions
end end

@ -0,0 +1,17 @@
<header>
<div class="logo">
<%= image_tag 'logo.png' %>
<span>
The Sins We Commit
</span>
</div>
<nav>
<% if current_user %>
<a href="<%= new_transgression_path %>">
Please me, mortal!
</a>
<% end %>
</nav>
</header>
<%= javascript_include_tag 'login_signup.js' %>

@ -7,6 +7,8 @@
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
</head> </head>
<body> <body>
<%= render partial: 'layouts/header' %>
<% if flash[:message] %> <% if flash[:message] %>
<div class="alert"> <div class="alert">
<%= flash[:message] %> <%= flash[:message] %>

@ -0,0 +1,3 @@
<% @transgressions.each do |trans| %>
<h5>For the sin of <%= trans.sin_type %>: <%= trans.description %></h5>
<% end %>

@ -0,0 +1,17 @@
<form action="<%= transgressions_path %>" method="POST"
class='transgression'>
<input type="hidden" name="authenticity_token"
value="<%= form_authenticity_token %>">
<input type="text" name="transgression[description]"
placeholder="Weaknesses are beautiful..."
value="<%= @transgression.description %>"><br/>
<select name="transgression[sin_type]">
<% Transgression::SIN_TYPES.each do |sin| %>
<option value="<%= sin %>"
<%= @transgression.sin_type == sin ? "selected" : "" %>>
<%= sin %>
</option>
<% end %>
</select>
<input type="submit" value="Here I am">
</form>

@ -8,4 +8,4 @@ Rails.application.config.assets.version = '1.0'
# Precompile additional assets. # Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # 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 )

@ -1,4 +1,5 @@
Rails.application.routes.draw do Rails.application.routes.draw do
resources :transgressions
root 'application#welcome' root 'application#welcome'
get '/amiloggedin' => 'application#amiloggedin' get '/amiloggedin' => 'application#amiloggedin'

@ -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

@ -11,11 +11,22 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" 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| create_table "users", force: :cascade do |t|
t.string "email", null: false t.string "email", null: false
t.string "password_digest", 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_index "users", ["email"], name: "index_users_on_email", using: :btree
add_foreign_key "transgressions", "users"
end end

@ -0,0 +1,7 @@
require 'test_helper'
class TransgressionsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

@ -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

@ -0,0 +1,7 @@
require 'test_helper'
class TransgressionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Loading…
Cancel
Save