Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
blog_comments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mis-21-2018-intersession
rails
blog_comments
Commits
a85840fd
Commit
a85840fd
authored
Jul 11, 2018
by
John Noel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished comments
parent
ee22f4fc
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
4 deletions
+53
-4
.keep
app/assets/javascripts/channels/.keep
+0
-0
comments_controller.rb
app/controllers/comments_controller.rb
+20
-1
new.html.erb
app/views/comments/new.html.erb
+7
-2
index.html.erb
app/views/posts/index.html.erb
+8
-1
show.html.erb
app/views/posts/show.html.erb
+18
-0
No files found.
app/assets/javascripts/channels/.keep
0 → 100644
View file @
a85840fd
app/controllers/comments_controller.rb
View file @
a85840fd
class
CommentsController
<
ApplicationController
class
CommentsController
<
ApplicationController
def
new
def
new
@post
=
Post
.
find_by
(
id:
params
[
:post_id
])
@comment
=
@post
.
comments
.
new
end
def
create
@post
=
Post
.
find_by
(
id:
params
[
:post_id
])
@comment
=
@post
.
comments
.
new
(
comment_params
)
@comment
.
user
=
current_user
if
@comment
.
save
redirect_to
post_path
(
@post
),
notice:
"Comment has been added."
else
render
'new'
end
end
private
def
comment_params
params
.
require
(
:comment
).
permit!
end
end
end
end
\ No newline at end of file
app/views/comments/new.html.erb
View file @
a85840fd
<h1>
Comments#new
</h1>
<h3>
New Comment
</h3>
<p>
Find me in app/views/comments/new.html.erb
</p>
Comment for:
<%=
@post
.
title
%>
<%=
simple_form_for
([
@post
,
@comment
])
do
|
f
|
%>
<%=
f
.
input
:comment
%>
<%=
f
.
button
:submit
,
"Add Comment"
%>
<%
end
%>
\ No newline at end of file
app/views/posts/index.html.erb
View file @
a85840fd
...
@@ -16,7 +16,8 @@
...
@@ -16,7 +16,8 @@
<th>
Title
</th>
<th>
Title
</th>
<th>
Content
</th>
<th>
Content
</th>
<th>
Posted by
</th>
<th>
Posted by
</th>
<th
colspan=
"3"
></th>
<th>
# of Comments
</th>
<th
colspan=
"4"
></th>
</thead>
</thead>
<tbody>
<tbody>
<%
@posts
.
each
do
|
post
|
%>
<%
@posts
.
each
do
|
post
|
%>
...
@@ -30,6 +31,9 @@
...
@@ -30,6 +31,9 @@
<td>
<td>
<%=
post
.
user
%>
<%=
post
.
user
%>
</td>
</td>
<td>
<%=
post
.
comments
.
count
%>
</td>
<td>
<td>
<%=
link_to
"Show"
,
post_path
(
post
),
class:
"btn btn-primary"
%>
<%=
link_to
"Show"
,
post_path
(
post
),
class:
"btn btn-primary"
%>
</td>
</td>
...
@@ -39,6 +43,9 @@
...
@@ -39,6 +43,9 @@
<td>
<td>
<%=
link_to
"Edit"
,
edit_post_path
(
post
),
class:
"btn btn-primary"
%>
<%=
link_to
"Edit"
,
edit_post_path
(
post
),
class:
"btn btn-primary"
%>
</td>
</td>
<td>
<%=
link_to
"Add Comment"
,
new_post_comment_path
(
post
),
class:
"btn btn-info"
%>
</td>
</tr>
</tr>
<%
end
%>
<%
end
%>
</tbody>
</tbody>
...
...
app/views/posts/show.html.erb
View file @
a85840fd
...
@@ -7,4 +7,22 @@
...
@@ -7,4 +7,22 @@
<%=
@post
.
content
%>
<%=
@post
.
content
%>
</p>
</p>
<ul>
<%
@post
.
comments
.
each
do
|
comment
|
%>
<li>
<%=
comment
.
comment
%>
<br>
<small>
<%=
comment
.
user
%>
<br>
<%=
time_ago_in_words
(
comment
.
created_at
)
%>
ago
</small>
</li>
<%
end
%>
</ul>
<%=
simple_form_for
([
@post
,
@post
.
comments
.
build
])
do
|
f
|
%>
<%=
f
.
input
:comment
%>
<%=
f
.
button
:submit
,
"Add Comment"
%>
<%
end
%>
<%=
link_to
"Back"
,
posts_path
,
class:
"btn btn-default"
%>
<%=
link_to
"Back"
,
posts_path
,
class:
"btn btn-default"
%>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment