Skip to content

Instantly share code, notes, and snippets.

@fullsailor
Created January 20, 2012 09:10
Show Gist options
  • Save fullsailor/1646308 to your computer and use it in GitHub Desktop.
Save fullsailor/1646308 to your computer and use it in GitHub Desktop.
<%= notice %>
<%= render 'form' %>
class PostsController < ApplicationController
# GET /posts
# posts
def index
@posts = Post.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @posts }
end
end
# GET /posts/new
# new_post
def new
@post = Post.new
respond_to do |format|
format.html
end
end
# POST /posts
def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save
format.html { redirect_to @post, notice: 'Post succesfully saved' }
else
format.html { render action: "new", notice: 'Error saving the post' }
end
end
end
# GET /posts/1
# post
def show
@post = Post.find(params[:id])
respond_to do |format|
format.html
end
end
# GET /posts/1/edit
# edit_post
def edit
@post = Post.find(params[:id])
respond_to do |format|
format.html
format.json
end
end
# PUT /posts/1
def update
@post = Post.find(params[:id])
respond_to do |format|
if @post.update_attributes(params[:post])
format.html { redirect_to @post, notice: 'Post successfully updated' }
else
format.html { render action: "edit", notice: 'Error saving the post' }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment