Commit 5e65ecdf authored by Henry Gonzales's avatar Henry Gonzales

winged dragon of ra

parent dce0e7c3
class AddUserToPosts < ActiveRecord::Migration
def change
add_column :posts, :user, :string
end
end
class AddUserIdToPosts < ActiveRecord::Migration
def change
add_column :posts, :user_id, :integer
end
end
source 'http://rubygems.org' source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5' gem 'rails', '4.2.6'
# Use sqlite3 as the database for Active Record # Use sqlite3 as the database for Active Record
gem 'sqlite3' gem 'sqlite3'
# Use SCSS for stylesheets # Use SCSS for stylesheets
...@@ -43,9 +43,18 @@ group :development do ...@@ -43,9 +43,18 @@ group :development do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring' gem 'spring'
gem 'simple_form'
gem 'devise'
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
end end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'simple_form'
gem 'devise'
GEM GEM
remote: http://rubygems.org/ remote: https://rubygems.org/
specs: specs:
actionmailer (4.2.5) actionmailer (4.2.6)
actionpack (= 4.2.5) actionpack (= 4.2.6)
actionview (= 4.2.5) actionview (= 4.2.6)
activejob (= 4.2.5) activejob (= 4.2.6)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.5) actionpack (4.2.6)
actionview (= 4.2.5) actionview (= 4.2.6)
activesupport (= 4.2.5) activesupport (= 4.2.6)
rack (~> 1.6) rack (~> 1.6)
rack-test (~> 0.6.2) rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.5) actionview (4.2.6)
activesupport (= 4.2.5) activesupport (= 4.2.6)
builder (~> 3.1) builder (~> 3.1)
erubis (~> 2.7.0) erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
activejob (4.2.5) activejob (4.2.6)
activesupport (= 4.2.5) activesupport (= 4.2.6)
globalid (>= 0.3.0) globalid (>= 0.3.0)
activemodel (4.2.5) activemodel (4.2.6)
activesupport (= 4.2.5) activesupport (= 4.2.6)
builder (~> 3.1) builder (~> 3.1)
activerecord (4.2.5) activerecord (4.2.6)
activemodel (= 4.2.5) activemodel (= 4.2.6)
activesupport (= 4.2.5) activesupport (= 4.2.6)
arel (~> 6.0) arel (~> 6.0)
activesupport (4.2.5) activesupport (4.2.6)
i18n (~> 0.7) i18n (~> 0.7)
json (~> 1.7, >= 1.7.7) json (~> 1.7, >= 1.7.7)
minitest (~> 5.1) minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4) thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
arel (6.0.3) arel (6.0.3)
bcrypt (3.1.11)
bcrypt (3.1.11-x86-mingw32) bcrypt (3.1.11-x86-mingw32)
binding_of_caller (0.7.2) binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1) debug_inspector (>= 0.0.1)
...@@ -92,16 +91,16 @@ GEM ...@@ -92,16 +91,16 @@ GEM
rack (1.6.4) rack (1.6.4)
rack-test (0.6.3) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
rails (4.2.5) rails (4.2.6)
actionmailer (= 4.2.5) actionmailer (= 4.2.6)
actionpack (= 4.2.5) actionpack (= 4.2.6)
actionview (= 4.2.5) actionview (= 4.2.6)
activejob (= 4.2.5) activejob (= 4.2.6)
activemodel (= 4.2.5) activemodel (= 4.2.6)
activerecord (= 4.2.5) activerecord (= 4.2.6)
activesupport (= 4.2.5) activesupport (= 4.2.6)
bundler (>= 1.3.0, < 2.0) bundler (>= 1.3.0, < 2.0)
railties (= 4.2.5) railties (= 4.2.6)
sprockets-rails sprockets-rails
rails-deprecated_sanitizer (1.0.3) rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha) activesupport (>= 4.2.0.alpha)
...@@ -111,9 +110,9 @@ GEM ...@@ -111,9 +110,9 @@ GEM
rails-deprecated_sanitizer (>= 1.0.1) rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3) rails-html-sanitizer (1.0.3)
loofah (~> 2.0) loofah (~> 2.0)
railties (4.2.5) railties (4.2.6)
actionpack (= 4.2.5) actionpack (= 4.2.6)
activesupport (= 4.2.5) activesupport (= 4.2.6)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rake (11.2.2) rake (11.2.2)
...@@ -152,7 +151,7 @@ GEM ...@@ -152,7 +151,7 @@ GEM
turbolinks-source (5.0.0) turbolinks-source (5.0.0)
tzinfo (1.2.2) tzinfo (1.2.2)
thread_safe (~> 0.1) thread_safe (~> 0.1)
tzinfo-data (1.2016.6) tzinfo-data (1.2016.5)
tzinfo (>= 1.0.0) tzinfo (>= 1.0.0)
uglifier (3.0.0) uglifier (3.0.0)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
...@@ -174,7 +173,7 @@ DEPENDENCIES ...@@ -174,7 +173,7 @@ DEPENDENCIES
devise devise
jbuilder (~> 2.0) jbuilder (~> 2.0)
jquery-rails jquery-rails
rails (= 4.2.5) rails (= 4.2.6)
sass-rails (~> 5.0) sass-rails (~> 5.0)
sdoc (~> 0.4.0) sdoc (~> 0.4.0)
simple_form simple_form
...@@ -186,4 +185,4 @@ DEPENDENCIES ...@@ -186,4 +185,4 @@ DEPENDENCIES
web-console (~> 2.0) web-console (~> 2.0)
BUNDLED WITH BUNDLED WITH
1.12.5 1.10.4
module Admin module Admin
class PostsController < ApplicationController class PostsController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
def index def index
@posts = Post.all @posts = Post.all
render "admin/posts/index.html.erb" render "admin/posts/index.html.erb"
...@@ -16,7 +15,7 @@ module Admin ...@@ -16,7 +15,7 @@ module Admin
@post = Post.find(params[:id]) @post = Post.find(params[:id])
if @post.update(post_params()) if @post.update(post_params())
redirect_to post_path(@post.id) redirect_to admin_post_path(@post.id)
else else
render "admin/posts/edit.html.erb" render "admin/posts/edit.html.erb"
end end
...@@ -31,7 +30,7 @@ module Admin ...@@ -31,7 +30,7 @@ module Admin
@post = Post.new(post_params()) @post = Post.new(post_params())
if @post.save if @post.save
redirect_to post_path(@post.id) redirect_to admin_post_path(@post.id)
else else
render "admin/posts/new.html.erb" render "admin/posts/new.html.erb"
end end
...@@ -46,7 +45,7 @@ module Admin ...@@ -46,7 +45,7 @@ module Admin
def destroy def destroy
@post = Post.find(params[:id]) @post = Post.find(params[:id])
@post.destroy! @post.destroy!
redirect_to posts_path redirect_to admin_posts_path
end end
def post_params def post_params
......
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception. # Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception protect_from_forgery with: :exception
end end
class PostsController < ApplicationController class PostsController < ApplicationController
before_filter :authenticate_user!, :except => [:show, :index] before_action :authenticate_user!
def index def index
@posts = Post.all @posts = Post.all
render "posts/index.html.erb" render "posts/index.html.erb"
...@@ -36,6 +37,7 @@ class PostsController < ApplicationController ...@@ -36,6 +37,7 @@ class PostsController < ApplicationController
def show def show
@post = Post.find(params[:id]) @post = Post.find(params[:id])
render "posts/show.html.erb" render "posts/show.html.erb"
end end
......
class Post < ActiveRecord::Base class Post < ActiveRecord::Base
validates :title, presence: true, uniqueness: true
validates :title, presence: true, uniqueness: true
validates :content, presence: true, uniqueness: true validates :content, presence: true, uniqueness: true
validates :published_at, presence: true validates :published_at, presence: true
......
class User < ActiveRecord::Base class User < ActiveRecord::Base
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
has_many :posts
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
has_many :posts
end end
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<%= f.input :published_at %> <%= f.input :published_at %>
<%= f.input :content %> <%= f.input :content %>
<%= f.input :is_published %> <%= f.input :is_published %>
<%= current_user.email %> <%= current_user.email %>
<%= f.submit %> <%= f.submit %>
<% end %> <% end %>
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<tr> <tr>
<th>Title</th> <th>Title</th>
<th>Published At</th> <th>Published At</th>
<th>Pusblished?</th> <th>Published?</th>
<th>Category ID</th> <th>Author</th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
<% @posts.each do |post| %> <% @posts.each do |post| %>
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<td><%= post.title %></td> <td><%= post.title %></td>
<td><%= post.published_at %></td> <td><%= post.published_at %></td>
<td><%= post.is_published %></td> <td><%= post.is_published %></td>
<td><%= post.category_id %></td> <td><%= current_user.email %></td>
<td> <td>
<%= link_to "Show", admin_post_path(post.id) %> <%= link_to "Show", admin_post_path(post.id) %>
<%= link_to "Edit", edit_admin_post_path(post.id) %> <%= link_to "Edit", edit_admin_post_path(post.id) %>
...@@ -24,6 +24,3 @@ ...@@ -24,6 +24,3 @@
</tr> </tr>
<% end %> <% end %>
</table> </table>
<%= link_to("Back to Home", root_path) %>
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
<%= render partial: "form" %> <%= render partial: "form" %>
<%= link_to "Back to Posts", admin_posts_path %> <%= link_to "Back to Posts", admin_posts_path %>
<h1><%= @post.title %></h1> <h1><%= @post.title %></h1>
<h3><%= @post.published_at %> by <%= current_user.email %> </h3> <h3><%= @post.published_at %></h3>
<p> <p>
<%= @post.content %> <%= @post.content %>
</p> </p>
<h3> Posted by: <%= current_user.email %></h3>
<hr> <hr>
<%= link_to "Back to Posts", admin_posts_path %> <%= link_to "Back to Posts", admin_posts_path %>
...@@ -4,6 +4,4 @@ ...@@ -4,6 +4,4 @@
<% @posts.each do |p| %> <% @posts.each do |p| %>
<li><%= link_to p.title, post_path(p.id) %></li> <li><%= link_to p.title, post_path(p.id) %></li>
<% end %> <% end %>
</ul> </ul>
\ No newline at end of file
<%= link_to("Back to Home", root_path) %>
<h2>Log in here pls</h2> <h2>Log in</h2>
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> <%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="form-inputs"> <div class="form-inputs">
......
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Bblog</title> <title>Blog</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
</head> </head>
<body> <body>
<% if user_signed_in? %> <% if user_signed_in? %>
good u are here <%= current_user.email %>! hello <%= current_user.email %>!
<%= link_to "Logout", destroy_user_session_path, method: :delete %> <%= link_to "Logout", destroy_user_session_path, method: :delete %>
<% else %> <% else %>
u not yet signed in pls sign in first
<%= link_to "Login", new_user_session_path %> <%= link_to "Login", new_user_session_path %>
<%= link_to "Register here!", new_user_registration_path %> <%= link_to "Register here!", new_user_registration_path %>
<% end %> <% end %>
......
<h1>My Blog</h1> <h1>My Blog</h1>
<%= link_to "Manage Posts", posts_path %> <%= link_to "Manage Posts", posts_path %>
<%= link_to "Add Posts", admin_posts_path %> <%= link_to "Manage Posts under Admin", admin_posts_path %>
<hr> <hr>
<% @categories.each do |c| %> <% @categories.each do |c| %>
......
...@@ -4,26 +4,21 @@ ...@@ -4,26 +4,21 @@
<th>Title</th> <th>Title</th>
<th>Category</th> <th>Category</th>
<th>Published At</th> <th>Published At</th>
<th>Pusblished?</th> <th>Published?</th>
<th>Category ID</th> <th>Author</th>
<th>Inputted by</th> <th>Actions</th>
</tr> </tr>
<% @posts.each do |post| %> <% @posts.each do |post| %>
<tr> <tr>
<td><%= post.title %></td> <td><%= post.title %></td>
<td><%= post.category.name %></td> <td><%= post.category.name %></td>
<td><%= post.published_at %></td> <td><%= post.published_at %></td>
<td><%= post.is_published %></td>
<td><%= post.category_id %></td>
<td><%= post.is_published %></td>
<td><%= current_user.email %></td>
<td> <td>
<%= link_to "Show", post_path(post.id) %> <%= link_to "Show", post_path(post.id) %>
</td> </td>
</tr> </tr>
<% end %> <% end %>
</table> </table>
<%= link_to("Back to Home", root_path) %>
<h1><%= @post.title %></h1> <h1><%= @post.title %></h1>
<h3><%= @post.published_at %> by <%= current_user.email %></h3> <h3><%= @post.published_at %></h3>
<p> <p>
<%= @post.content %> <%= @post.content %>
</p> </p>
<h3>Posted by: <%= current_user.email %></h3>
<hr> <hr>
<%= link_to "Back to Posts", posts_path %> <%= link_to "Back to Posts", posts_path %>
...@@ -6,7 +6,7 @@ require 'rails/all' ...@@ -6,7 +6,7 @@ require 'rails/all'
# you've limited to :test, :development, or :production. # you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups) Bundler.require(*Rails.groups)
module Bblog module Blog
class Application < Rails::Application class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers
......
...@@ -6,7 +6,7 @@ Devise.setup do |config| ...@@ -6,7 +6,7 @@ Devise.setup do |config|
# confirmation, reset password and unlock tokens in the database. # confirmation, reset password and unlock tokens in the database.
# Devise will use the `secret_key_base` as its `secret_key` # Devise will use the `secret_key_base` as its `secret_key`
# by default. You can change it below and use your own secret key. # by default. You can change it below and use your own secret key.
# config.secret_key = '3fbf08dc09fb7c37733f3679ae07f31a0d09ab01fdbc4f96bfcb4c9995c461797abc82d44b757de200daae77b0a72d6c0d7367661218971898b9236661436912' # config.secret_key = '616e96f5877073d5b33b33c45a2e027f216d4cd1d346214ae79620801a4349013b3c5be5777756647882f1eac34f068c1dcb9de80387d2dbf29e6a05f68b7125'
# ==> Mailer Configuration # ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer, # Configure the e-mail address which will be shown in Devise::Mailer,
...@@ -108,7 +108,7 @@ Devise.setup do |config| ...@@ -108,7 +108,7 @@ Devise.setup do |config|
config.stretches = Rails.env.test? ? 1 : 11 config.stretches = Rails.env.test? ? 1 : 11
# Set up a pepper to generate the hashed password. # Set up a pepper to generate the hashed password.
# config.pepper = '801d5d8e855df5f8f6d091ae6c0907d41649577bffea24736256ee9d0daa4cd413144c662310b4b88987207dd447f11690de9fb4bafb36a1a84905f2bec0d136' # config.pepper = '9f22c4eebcc6bc2e7342ded64283bf8b2c2bddf4f59599ffb0641b223499ac5394f59ee26d969f674489beef6024dc6370cb387a30418324f522940f8b91cae9'
# Send a notification email when the user's password is changed # Send a notification email when the user's password is changed
# config.send_password_change_notification = false # config.send_password_change_notification = false
......
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, key: '_bblog_session' Rails.application.config.session_store :cookie_store, key: '_blog_session'
...@@ -2,9 +2,10 @@ Rails.application.routes.draw do ...@@ -2,9 +2,10 @@ Rails.application.routes.draw do
devise_for :users devise_for :users
root to: "pages#index" root to: "pages#index"
resources :posts resources :posts
get "/categories/:id", to: "categories#show" get "/categories/:id", to: "categories#show"
get 'users/:id/posts' => 'users#posts', :as => :user_posts get 'users/:id/posts' => 'users#posts', :as => :user_posts
namespace :admin do namespace :admin do
resources :posts resources :posts
end end
end end
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
# if you're sharing your code publicly. # if you're sharing your code publicly.
development: development:
secret_key_base: 15b6d6baa7191c910b6580d4426612b77db190bdf54b83f583a11ab42cb548cbbf9080736fb9625df647d86623e815768a34567b1e8fa4cd5c6857170b5ab412 secret_key_base: db26b7753500999333071789eac4a6f2bdc3f2c4eda341e1ab89bfc66839685cb1de9c984ac4748080d886128dfd0926da8307c817f4095c6101a085c2d11b3c
test: test:
secret_key_base: 81daec825a8de6fb91aa14a7ad4afe24348e2c14708ae2451c2fbdf7c936e9f8efe6651374cc26c00d0d2fbcfb563e5f86c1a82e69996f3e826070273eaa4e83 secret_key_base: 7b6a6bfe9ff738db189ed670b744e8c07aa09b3539f88c9f64889139b9eb70776aa0b83badede1d1f30c1d6ade6f7673e034c362a3770c6561c649d55a7d2b6d
# Do not keep production secrets in the repository, # Do not keep production secrets in the repository,
# instead read values from the environment. # instead read values from the environment.
......
class AddCategoryToPosts < ActiveRecord::Migration class AddCategoryToPosts < ActiveRecord::Migration
def change def change
add_column :posts, :category, :string add_column :posts, :category, :string
end end
end end
...@@ -2,6 +2,5 @@ class ChangePostsTable < ActiveRecord::Migration ...@@ -2,6 +2,5 @@ class ChangePostsTable < ActiveRecord::Migration
def change def change
remove_column :posts, :category remove_column :posts, :category
add_column :posts, :category_id, :integer add_column :posts, :category_id, :integer
end end
end end
class DeviseCreateUsers < ActiveRecord::Migration class DeviseCreateUsers < ActiveRecord::Migration
def change def change
create_table(:users) do |t| create_table :users do |t|
## Database authenticatable ## Database authenticatable
t.string :email, null: false, default: "" t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: "" t.string :encrypted_password, null: false, default: ""
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# 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: 20160716055326) do ActiveRecord::Schema.define(version: 20160716113540) do
create_table "categories", force: :cascade do |t| create_table "categories", force: :cascade do |t|
t.string "name" t.string "name"
...@@ -27,8 +27,6 @@ ActiveRecord::Schema.define(version: 20160716055326) do ...@@ -27,8 +27,6 @@ ActiveRecord::Schema.define(version: 20160716055326) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "category_id" t.integer "category_id"
t.string "user"
t.integer "user_id"
end end
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
one: one:
title: MyString title: MyString
content: MyText content: MyText
published_at: 2016-07-16 published_at: 2016-07-11
is_published: false is_published: false
two: two:
title: MyString title: MyString
content: MyText content: MyText
published_at: 2016-07-16 published_at: 2016-07-11
is_published: false is_published: false
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment