Last active
January 2, 2016 10:59
-
-
Save sranso/8293958 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in config/routes.rb | |
RailsSampleApp::Application.routes.draw do | |
resources :posts | |
# SHORTCUT VERB ROUTE CONTROLLER#ACTION | |
# posts GET /posts(.:format) posts#index | |
# POST /posts(.:format) posts#create | |
# new_post GET /posts/new(.:format) posts#new | |
# edit_post GET /posts/:id/edit(.:format) posts#edit | |
# post GET /posts/:id(.:format) posts#show | |
# PUT /posts/:id(.:format) posts#update | |
# DELETE /posts/:id(.:format) posts#destroy | |
# in app/controllers/posts_controller.rb | |
class PostsController < ApplicationController | |
# GET /posts | |
def index | |
@posts = Post.all | |
end | |
# GET /posts/1 | |
def show | |
@post = Post.find(params[:id]) | |
end | |
# GET /posts/new | |
def new | |
@post = Post.new | |
end | |
# GET /posts/1/edit | |
def edit | |
@post = Post.find(params[:id]) | |
end | |
# POST /posts | |
def create | |
@post = Post.new(params[:post]) | |
redirect_to @post | |
end | |
# PUT /posts/1 | |
def update | |
@post = Post.find(params[:id]) | |
end | |
# DELETE /posts/1 | |
def destroy | |
@post = Post.find(params[:id]) | |
@post.destroy | |
redirect_to "/posts" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment