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