Commit c20af6ef authored by John Noel's avatar John Noel

Finished setup of models

parent 5268e222
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
// Place all the styles related to the Comments controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class CommentsController < ApplicationController
def new
end
end
module CommentsHelper
end
class Comment < ApplicationRecord
belongs_to :user
belongs_to :post
end
\ No newline at end of file
class Post < ApplicationRecord class Post < ApplicationRecord
belongs_to :user belongs_to :user
has_many :comments
end end
\ No newline at end of file
...@@ -4,6 +4,7 @@ class User < ApplicationRecord ...@@ -4,6 +4,7 @@ class User < ApplicationRecord
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
has_many :posts has_many :posts
has_many :comments
def to_s def to_s
if first_name && last_name if first_name && last_name
......
<h1>Comments#new</h1>
<p>Find me in app/views/comments/new.html.erb</p>
Rails.application.routes.draw do Rails.application.routes.draw do
get 'comments/new'
devise_for :users devise_for :users
devise_scope :user do devise_scope :user do
authenticated :user do authenticated :user do
......
class CreateComments < ActiveRecord::Migration[5.2]
def change
create_table :comments do |t|
t.text :comment
t.references :user, foreign_key: true
t.references :post, foreign_key: true
t.timestamps
end
end
end
require 'test_helper'
class CommentsControllerTest < ActionDispatch::IntegrationTest
test "should get new" do
get comments_new_url
assert_response :success
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
comment: MyText
user: one
post: one
two:
comment: MyText
user: two
post: two
require 'test_helper'
class CommentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
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