Created
January 20, 2012 09:10
-
-
Save fullsailor/1646308 to your computer and use it in GitHub Desktop.
This file contains 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
<%= notice %> | |
<%= render 'form' %> |
This file contains 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
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