Class: Notee::PostsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Notee::PostsController
- Defined in:
- app/controllers/notee/posts_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /posts.
-
#destroy ⇒ Object
DELETE /posts/1.
-
#index ⇒ Object
GET /posts.
-
#show ⇒ Object
GET /posts/1.
-
#update ⇒ Object
PATCH/PUT /posts/1.
Methods inherited from ApplicationController
#restrict_access_json, #set_request_filter
Instance Method Details
#create ⇒ Object
POST /posts
20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/notee/posts_controller.rb', line 20 def create @post = Post.new(post_params) @post.set_user_id respond_to do |format| if @post.save format.json { render json: @post, status: 200 } else format.json { render json: @post.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /posts/1
45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/notee/posts_controller.rb', line 45 def destroy respond_to do |format| if @post.update(is_deleted: true) format.json { render json: @post, status: 200 } else format.json { render json: @post.errors, status: :internal_server_error } end end end |
#index ⇒ Object
GET /posts
9 10 11 12 |
# File 'app/controllers/notee/posts_controller.rb', line 9 def index @posts = Post.where(is_deleted: false).order(updated_at: :desc) render json: { status: 'success', posts: @posts } end |
#show ⇒ Object
GET /posts/1
15 16 17 |
# File 'app/controllers/notee/posts_controller.rb', line 15 def show render json: { status: 'success', post: @post} end |
#update ⇒ Object
PATCH/PUT /posts/1
33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/notee/posts_controller.rb', line 33 def update post_params[:user_id] = @post.user_id respond_to do |format| if @post.update(post_params) format.json { render json: @post, status: 200 } else format.json { render json: @post.errors, status: :unprocessable_entity } end end end |