Skip to content

Commit

Permalink
Fixed the bug, turns out I didn't add a refernce to article when gene…
Browse files Browse the repository at this point in the history
…rating the model. Basic comment display now working, next to add writing capability
  • Loading branch information
thomas-xza committed Jul 22, 2024
1 parent 149008b commit baf4e8c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
4 changes: 2 additions & 2 deletions rails_app/app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class CommentsController < ApplicationController

def create

@project = Project.find(params[:project_id])
@project = Project.find(params[:id])

@comment = @project.comments.create(comment_params)

Expand All @@ -16,7 +16,7 @@ def create

def comment_params

params.require(:comment).permit(:commenter, :body)
params.require(:comment).permit(:creator, :body)

end

Expand Down
24 changes: 22 additions & 2 deletions rails_app/app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@

<p>Project status: <%= @project.status %></p>



<h2>Add a comment:</h2>

<%= form_with model: [ @project, @project.comments.build ] do |form| %>

<p>
<%= form.label :commenter %><br>
<%= form.text_field :commenter %>
<%= form.label :creator %><br>
<%= form.text_field :creator %>
</p>

<p>
<%= form.label :tag %><br>
<%= form.text_field :tag %>
</p>

<p>
Expand All @@ -23,3 +30,16 @@
</p>

<% end %>


<% @project.comments.each do |comment| %>
<p>
<strong>Commenter:</strong>
<%= comment.creator %>
</p>

<p>
<strong>Comment:</strong>
<%= comment.body %>
</p>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class AddProjectIdToComments < ActiveRecord::Migration[7.1]
def change
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddProjectRefToComment < ActiveRecord::Migration[7.1]
def change
add_reference :comments, :project, null: false, foreign_key: true
end
end
14 changes: 13 additions & 1 deletion rails_app/db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions rails_app/test/controllers/comments_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "test_helper"

class CommentsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

0 comments on commit baf4e8c

Please sign in to comment.