Class: PostsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PostsController
- Defined in:
- app/controllers/posts_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /posts or /posts.json.
-
#destroy ⇒ Object
DELETE /posts/1 or /posts/1.json.
-
#edit ⇒ Object
GET /posts/1/edit.
-
#index ⇒ Object
GET /posts or /posts.json.
-
#new ⇒ Object
GET /posts/new.
-
#show ⇒ Object
GET /posts/1 or /posts/1.json.
-
#update ⇒ Object
PATCH/PUT /posts/1 or /posts/1.json.
Instance Method Details
#create ⇒ Object
POST /posts or /posts.json
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/posts_controller.rb', line 23 def create @post = Post.new(post_params) respond_to do |format| if @post.save format.html { redirect_to @post, notice: "Post was successfully created." } format.json { render :show, status: :created, location: @post } else format.html { render :new, status: :unprocessable_entity } format.json { render json: @post.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /posts/1 or /posts/1.json
51 52 53 54 55 56 57 |
# File 'app/controllers/posts_controller.rb', line 51 def destroy @post.destroy respond_to do |format| format.html { redirect_to posts_url, notice: "Post was successfully destroyed." } format.json { head :no_content } end end |
#edit ⇒ Object
GET /posts/1/edit
19 20 |
# File 'app/controllers/posts_controller.rb', line 19 def edit end |
#index ⇒ Object
GET /posts or /posts.json
5 6 7 |
# File 'app/controllers/posts_controller.rb', line 5 def index @posts = Post.all end |
#new ⇒ Object
GET /posts/new
14 15 16 |
# File 'app/controllers/posts_controller.rb', line 14 def new @post = Post.new end |
#show ⇒ Object
GET /posts/1 or /posts/1.json
10 11 |
# File 'app/controllers/posts_controller.rb', line 10 def show end |
#update ⇒ Object
PATCH/PUT /posts/1 or /posts/1.json
38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/posts_controller.rb', line 38 def update respond_to do |format| if @post.update(post_params) format.html { redirect_to @post, notice: "Post was successfully updated." } format.json { render :show, status: :ok, location: @post } else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @post.errors, status: :unprocessable_entity } end end end |