Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ae727ac
Initial commit to branch
MrPranklin Dec 23, 2018
78b7a4d
Installed annotate gem, annotated
MrPranklin Dec 23, 2018
76e9412
Remove excess controller
MrPranklin Dec 23, 2018
b9d84b6
Created SubReddit model, migrated
MrPranklin Dec 23, 2018
fd96cd6
Added columns to posts database
MrPranklin Dec 23, 2018
0d8d9e3
Change drop_authors, add create_users
MrPranklin Dec 23, 2018
0df4306
ocnvert comment associations to references'
MrPranklin Dec 23, 2018
80dc0fb
Finish tutorial
MrPranklin Dec 23, 2018
5f062cb
Add things missed in chapter, spelling
MrPranklin Dec 24, 2018
28880e9
FInished 6th task in 5th assignment
MrPranklin Dec 24, 2018
9feae30
Add upvote model, important changes
MrPranklin Dec 24, 2018
f14a7c1
Add associations
MrPranklin Dec 24, 2018
5d29943
Migrated all tasks, annotated
MrPranklin Dec 25, 2018
a818100
Destroy authors, create user controller and rest
MrPranklin Dec 25, 2018
d5a17fd
Add title and subreddit print
MrPranklin Dec 25, 2018
b14bd2e
Remove old, wrong solutions
MrPranklin Dec 25, 2018
2a29c9d
Tried to change input for post creation
MrPranklin Dec 25, 2018
957b520
Really dumb way of refactoring
MrPranklin Dec 25, 2018
df5f665
Add mock routes for users
MrPranklin Dec 25, 2018
5a4f6c9
Configure user routes, views and controller
MrPranklin Dec 25, 2018
485ada5
Added message to post show view
MrPranklin Dec 25, 2018
417b21c
Added print to views
MrPranklin Dec 25, 2018
2b173f9
Add newly added columns to print
MrPranklin Dec 25, 2018
fd2c1e4
Removed empty line
MrPranklin Dec 25, 2018
98bd2c7
Merge branch 'master' into feature/fifth-assignment
MrPranklin Jan 14, 2019
0a23b16
Change belongs_to :user to :owner
MrPranklin Jan 17, 2019
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
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,22 @@

# Ignore master key for decrypting credentials and more.
/config/master.key

# ---Vim stuff---
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'annotate'
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ GEM
tzinfo (~> 1.1)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
annotate (2.7.4)
activerecord (>= 3.2, < 6.0)
rake (>= 10.4, < 13.0)
archive-zip (0.11.0)
io-like (~> 0.3.0)
arel (9.0.0)
Expand Down Expand Up @@ -209,6 +212,7 @@ PLATFORMS
ruby

DEPENDENCIES
annotate
bootstrap
byebug
capybara (>= 2.15)
Expand Down Expand Up @@ -236,4 +240,4 @@ RUBY VERSION
ruby 2.5.1p57

BUNDLED WITH
1.16.6
1.17.2
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Place all the styles related to the Authors controller here.
// Place all the styles related to the users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
74 changes: 0 additions & 74 deletions app/controllers/authors_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ def set_post

# Never trust parameters from the scary internet, only allow the white list through.
def post_params
params.require(:post).permit(:author_id, :content, :published)
params.require(:post).permit(:author_id, :title, :sub_reddit_id, :content, :published)
end
end
15 changes: 15 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class UsersController < ApplicationController
def index
@users = User.all
end

def show
@user = User.find_by( id: params[:id] )
end

def new
@user = User.new
end
end
2 changes: 0 additions & 2 deletions app/helpers/authors_helper.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UsersHelper
end
2 changes: 0 additions & 2 deletions app/models/author.rb

This file was deleted.

16 changes: 16 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
# == Schema Information
#
# Table name: comments
#
# id :integer not null, primary key
# post_id :integer
# author_id :integer
# content :text
# created_at :datetime not null
# updated_at :datetime not null
#

class Comment < ApplicationRecord
belongs_to :post
belongs_to :author, class_name: 'User'

validates :content, presence: true, length: { minimum: 2 }
end
22 changes: 22 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: posts
#
# id :integer not null, primary key
# author_id :integer not null
# content :text
# published :boolean
# created_at :datetime not null
# updated_at :datetime not null
# title :string default(""), not null
# sub_reddit_id :integer
#

class Post < ApplicationRecord
has_many :comments
has_many :upvotes
belongs_to :user
belongs_to :sub_reddits

validates :title, presence: true, uniqueness: true
validates :sub_reddit_id, presence: true
end
21 changes: 21 additions & 0 deletions app/models/sub_reddit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# == Schema Information
#
# Table name: sub_reddits
#
# id :integer not null, primary key
# title :string not null
# description :text not null
# private :boolean default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
# owner_id :integer
#

class SubReddit < ApplicationRecord
belongs_to :user
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the user owner?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that a SubReddit must have been created by someone, so the creator (a User) would be it's owner. If that's not the case, was the expected solution that every SubReddit owns many Users (a.k.a. has subscribers) and every User belongs to many SubReddits (a.k.a. is subscribed to many)?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but this by default makes rails look for user_id. If you want to access your user as an "owner" method, you need specify it like belongs_to :owner, class_name: 'User'

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are any database changes necessary for this or is that it?

has_many :posts

validates :title, presence: true, uniqueness: true
validates :owner, presence: true
validates :description, presence: true
end
20 changes: 20 additions & 0 deletions app/models/upvote.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# == Schema Information
#
# Table name: upvotes
#
# id :integer not null, primary key
# creator :string not null
# post :string not null
# created_at :datetime not null
# updated_at :datetime not null
# creator_id :integer
# post_id :integer
#

class Upvote < ApplicationRecord
belongs_to :user
belongs_to :post

validates :post, presence: true
validates :creator, uniqueness: true, presence: true
end
19 changes: 19 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# email :string not null
# username :string not null
# created_at :datetime not null
# updated_at :datetime not null
#

class User < ApplicationRecord
has_many :comments, foreign_key: 'author_id'
has_many :sub_reddits
has_many :posts
has_many :upvotes

validates :email, uniqueness: { scope: :username } , presence: true
end
2 changes: 0 additions & 2 deletions app/views/authors/_author.json.jbuilder

This file was deleted.

15 changes: 0 additions & 15 deletions app/views/authors/_form.html.erb

This file was deleted.

6 changes: 0 additions & 6 deletions app/views/authors/edit.html.erb

This file was deleted.

31 changes: 0 additions & 31 deletions app/views/authors/index.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/authors/index.json.jbuilder

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/authors/new.html.erb

This file was deleted.

19 changes: 0 additions & 19 deletions app/views/authors/show.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/authors/show.json.jbuilder

This file was deleted.

8 changes: 7 additions & 1 deletion app/views/comments/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<p id="notice"><%= notice %></p>

<h1>Comments</h1>

<% @comments.each do |comment| %>
<t%= comment.post_id %>
<% end %>
<table>
<thead>
<tr>
<th>Post</th>
<th>Author</th>
<th>Content</th>
<th>Created at:</th>
<th>Updated at:</th>
<th colspan="3"></th>
</tr>
</thead>
Expand All @@ -18,6 +22,8 @@
<td><%= comment.post_id %></td>
<td><%= comment.author_id %></td>
<td><%= comment.content %></td>
<td><%= comment.created_at %></td>
<td><%= comment.updated_at %></td>
<td><%= link_to 'Show', comment %></td>
<td><%= link_to 'Edit', edit_comment_path(comment) %></td>
<td><%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you sure?' } %></td>
Expand Down
2 changes: 0 additions & 2 deletions app/views/comments/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
<%= render 'form', comment: @comment %>

<%= link_to 'Back', comments_path %>

<h2>Solve captcha!</h2>
Loading