mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 03:07:52 +01:00
Add comments controller and routes
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
// Place all the styles related to the posts controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
11
app/controllers/comments_controller.rb
Normal file
11
app/controllers/comments_controller.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class CommentsController < ApplicationController
|
||||
def index
|
||||
comments = Comment
|
||||
.where(post_id: params[:post_id])
|
||||
.left_outer_joins(:user)
|
||||
.select('comments.body, comments.updated_at, users.full_name')
|
||||
.order(updated_at: :desc)
|
||||
|
||||
render json: comments
|
||||
end
|
||||
end
|
||||
2
app/helpers/comments_helper.rb
Normal file
2
app/helpers/comments_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module CommentsHelper
|
||||
end
|
||||
@@ -2,6 +2,7 @@ class Post < ApplicationRecord
|
||||
belongs_to :board
|
||||
belongs_to :user
|
||||
belongs_to :post_status, optional: true
|
||||
has_many :comments
|
||||
|
||||
validates :title, presence: true, length: { in: 4..64 }
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ class User < ApplicationRecord
|
||||
:recoverable, :rememberable, :validatable,
|
||||
:confirmable
|
||||
|
||||
has_many :comments
|
||||
|
||||
enum role: [:user, :moderator, :admin]
|
||||
after_initialize :set_default_role, if: :new_record?
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ Rails.application.routes.draw do
|
||||
devise_for :users
|
||||
|
||||
resources :boards, only: [:show]
|
||||
resources :posts, only: [:index, :create, :show, :update]
|
||||
resources :posts, only: [:index, :create, :show, :update] do
|
||||
resources :comments, only: [:index]
|
||||
end
|
||||
resources :post_statuses, only: [:index]
|
||||
end
|
||||
|
||||
@@ -13,20 +13,20 @@ completed_post_status = PostStatus.create(name: 'Completed', color: '#6ac47c', o
|
||||
rejected_post_status = PostStatus.create(name: 'Rejected', color: '#ff2600', order: 4, show_in_roadmap: false)
|
||||
|
||||
# Create some posts
|
||||
Post.create(
|
||||
post1 = Post.create(
|
||||
title: 'This is how users give you feedback',
|
||||
description: 'They can also provide an extendend description like this... bla bla...',
|
||||
board_id: feature_board.id,
|
||||
user_id: admin.id
|
||||
)
|
||||
Post.create(
|
||||
post2 = Post.create(
|
||||
title: 'You can assign a status to each post',
|
||||
description: 'This one, for example, is marked as "Planned"',
|
||||
board_id: feature_board.id,
|
||||
user_id: admin.id,
|
||||
post_status_id: planned_post_status.id
|
||||
)
|
||||
Post.create(
|
||||
post3 = Post.create(
|
||||
title: 'There are multiple boards',
|
||||
description: 'For now you have Feature Requests and Bug Reports, but you can add or remove as many as you want!',
|
||||
board_id: bug_board.id,
|
||||
@@ -34,6 +34,9 @@ Post.create(
|
||||
post_status_id: in_progress_post_status.id
|
||||
)
|
||||
|
||||
# Create some comments
|
||||
post1.comments.create(body: 'Users can comment to express their opinions!', user_id: admin.id)
|
||||
|
||||
# Let the user know how to log in with admin account
|
||||
puts 'A default admin account has been created. Credentials:'
|
||||
puts "-> email: #{admin.email}"
|
||||
|
||||
Reference in New Issue
Block a user