Class: Notee::PostsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/notee/posts_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#restrict_access_json

Instance Method Details

#createObject

POST /posts



20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/notee/posts_controller.rb', line 20

def create
  @post = Post.new(post_params)
  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

#destroyObject

DELETE /posts/1



43
44
45
46
# File 'app/controllers/notee/posts_controller.rb', line 43

def destroy
  @post.destroy
  render json: { status: 'success' }
end

#indexObject

GET /posts



9
10
11
12
# File 'app/controllers/notee/posts_controller.rb', line 9

def index
  @posts = Post.all.order(updated_at: :desc)
  render json: { status: 'success', posts: @posts }
end

#showObject

GET /posts/1



15
16
17
# File 'app/controllers/notee/posts_controller.rb', line 15

def show
  render json: { status: 'success', post: @post}
end

#updateObject

PATCH/PUT /posts/1



32
33
34
35
36
37
38
39
40
# File 'app/controllers/notee/posts_controller.rb', line 32

def update
  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