Class: Unsakini::PostsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Unsakini::PostsController
- Includes:
- ActionController::Serialization, BoardOwnerControllerConcern, LoggedInControllerConcern, PostOwnerControllerConcern
- Defined in:
- app/controllers/unsakini/posts_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
Creates a single post belonging to the board.
-
#destroy ⇒ Object
Deletes a single post belonging to the board.
-
#index ⇒ Object
Renders the post belonging to the board.
-
#show ⇒ Object
Renders a single post belonging to the board.
-
#update ⇒ Object
Updates a single post belonging to the board.
Methods included from PostOwnerControllerConcern
#ensure_post, #ensure_post_owner, #has_post_access
Methods included from BoardOwnerControllerConcern
#ensure_board, #ensure_board_owner, #has_board_access
Instance Method Details
#create ⇒ Object
Creates a single post belonging to the board
‘POST /api/boards/:board_id/posts/`
30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/unsakini/posts_controller.rb', line 30 def create @post = Post.new(params.permit(:title, :content, :board_id)) @post.user = @user if (@post.save) render json: @post, status: :created else render json: @post.errors, status: 422 end end |
#destroy ⇒ Object
Deletes a single post belonging to the board
‘DELETE /api/boards/:board_id/posts/:id`
54 55 56 57 |
# File 'app/controllers/unsakini/posts_controller.rb', line 54 def destroy @post.destroy render json: {}, status: :ok end |
#index ⇒ Object
Renders the post belonging to the board
‘GET /api/boards/:board_id/posts`
16 17 18 |
# File 'app/controllers/unsakini/posts_controller.rb', line 16 def index paginate json: @board.posts.page(params[:page]), per_page: 20 end |
#show ⇒ Object
Renders a single post belonging to the board
‘GET /api/boards/:board_id/posts/:id`
23 24 25 |
# File 'app/controllers/unsakini/posts_controller.rb', line 23 def show render json: @post end |
#update ⇒ Object
Updates a single post belonging to the board
‘PUT /api/boards/:board_id/posts/:id`
43 44 45 46 47 48 49 |
# File 'app/controllers/unsakini/posts_controller.rb', line 43 def update if (@post.update(params.permit(:title, :content))) render json: @post, status: :ok else render json: @post.errors, status: 422 end end |