forked from makersacademy/acebook-rails-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from NenehB/adding_comments
Adding comments
- Loading branch information
Showing
27 changed files
with
205 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ | |
*= require_tree . | ||
*= require_self | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the comments controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: https://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class CommentsController < ApplicationController | ||
|
||
def new | ||
@comment = Comment.new | ||
end | ||
|
||
def create | ||
@comment = Comment.create(comment: comments_params["comment"], post_id: id_params) | ||
redirect_to posts_url | ||
end | ||
|
||
def index | ||
@comment = Comment.new | ||
end | ||
|
||
private | ||
|
||
def comments_params | ||
params.require(:comment).permit(:comment) | ||
end | ||
|
||
def id_params | ||
params.require(:post_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module CommentsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Comment < ApplicationRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
class Post < ApplicationRecord | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,46 +8,54 @@ | |
<!-- Bootstrap CSS --> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> | ||
|
||
</head> | ||
<body> | ||
</head> | ||
<body> | ||
|
||
<nav class="navbar navbar-dark bg-primary"> | ||
<div class="container-fluid"> | ||
<a class="navbar-brand">Acebook</a> | ||
<form class="d-flex"> | ||
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"> | ||
<button class="btn btn-outline-success" type="submit">Search</button> | ||
</form> | ||
</div> | ||
</nav> | ||
<nav class="navbar navbar-dark bg-primary"> | ||
<div class="container-fluid"> | ||
<a class="navbar-brand">Acebook</a> | ||
<form class="d-flex"> | ||
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"> | ||
<button class="btn btn-outline-success" type="submit">Search</button> | ||
</form> | ||
</div> | ||
</nav> | ||
|
||
<ul class="nav justify-content-end"> | ||
<li class="nav-item"> | ||
<ul class="nav justify-content-end"> | ||
<li class="nav-item"> | ||
<a class="nav-link active" aria-current="page" href="#">Home</a> | ||
</li> | ||
<li class="nav-item"> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="#">Profile</a> | ||
</li> | ||
<li class="nav-item"> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="#">Settings</a> | ||
</li> | ||
<li class="nav-item"> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="#">Sign Out</a> | ||
</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
|
||
<p1 class="h2 offset-1"> <%= link_to new_post_path do %> | ||
Write a post | ||
<% end %> </p1> | ||
|
||
<div class="center" | ||
<div class="mb-3 offset-4" style="text-align: center;"> | ||
<label for="post" class="form-label"> <h4>Whats on your mind?</h4></label> | ||
<textarea class="form-control offset-4" id="exampleFormControlTextarea1" rows="4" style="width: 40rem;"></textarea> | ||
<div class="row"> | ||
<br> | ||
<div class="container"> | ||
<div class = "row"> | ||
<div class="center" style="width: 50rem;"> | ||
<div class="form-control offset-4" style="text-align: center;"> | ||
<label for="post" class="form-label"> <h4>Whats on your mind?</h4></label> | ||
<%= form_for @post, html: {class: 'form-control offsetWidth-8'} do |form| %> | ||
<%= form.label 'message' %> | ||
<%= form.text_field :message %> | ||
<%= form.submit "Submit" %> | ||
<% end %> | ||
<div class="row"> | ||
<br> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<br> | ||
</div> | ||
|
||
<% @posts.each do |post| %> | ||
|
@@ -56,28 +64,57 @@ | |
<div class="card" style="width: 30rem;"> | ||
<div class="card-body"> | ||
<h5 class="card-title">Users name</h5> | ||
<h6 class="card-subtitle mb-2 text-muted">26/11/2021</h6> | ||
<h6 class="card-subtitle mb-2 text-muted"><%= post.created_at %></h6> | ||
<p class="card-text"><%= post.message %></p> | ||
|
||
|
||
|
||
|
||
<%= button_to (post.likes.to_s + ' Likes'), post_path(post.id), :method => :patch %> | ||
</div> | ||
|
||
|
||
<%= form_for @comment, html: {class: 'form-control offsetWidth-8'} do |form| %> | ||
<%= form.label 'comment' %> | ||
<%= form.text_field :comment %> | ||
<%= hidden_field_tag :post_id, post.id %> | ||
<%= form.submit "Submit comment" %> | ||
<% end %> | ||
|
||
<a href="#" class="card-link">Comment</a> | ||
<div class="row"> | ||
<br> | ||
</div> | ||
</div> | ||
|
||
<% @posts_comments.each do |comments| %> | ||
<% if comments.post_id == post.id %> | ||
<div class="container"> | ||
<div class ="row"> | ||
<div class="card" style="width: 30rem;"> | ||
<p> User Name </p> | ||
<%= comments.created_at %> <br> | ||
<%= comments.comment %> | ||
<div class="row"> | ||
<br> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> | ||
<div class="row"> | ||
<br> | ||
</div> | ||
<% end %> | ||
|
||
<div class="row"> | ||
<br> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<br> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
<% end %> | ||
|
||
|
||
</body> | ||
</html> | ||
</div> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,10 @@ | |
<body> | ||
|
||
|
||
|
||
|
||
|
||
|
||
<%= form_for @post do |form| %> | ||
<%= form.label :message %> | ||
<%= form.text_field :message %> | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,5 @@ | |
resources :sessions | ||
resources :users | ||
resources :posts | ||
|
||
resources :comments | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ def change | |
create_table :posts do |t| | ||
t.string :message | ||
t.timestamps | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class NewCommentTable < ActiveRecord::Migration[6.0] | ||
def change | ||
create_table :comments do |t| | ||
t.integer :user_id | ||
t.integer :post_id | ||
t.string :comment | ||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.feature "Comments", type: :feature do | ||
scenario "User can comment on a post" do | ||
visit "/posts" | ||
fill_in "Message", with: "Hello, world!" | ||
click_button "Submit" | ||
fill_in "Comment", with: "Nice one!" | ||
click_button "Submit comment" | ||
expect(page).to have_content("Nice one!") | ||
end | ||
end |
Oops, something went wrong.