Skip to content

Instantly share code, notes, and snippets.

Created April 6, 2013 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5327873 to your computer and use it in GitHub Desktop.
Save anonymous/5327873 to your computer and use it in GitHub Desktop.
articles_controller.rb
class ArticlesController < ApplicationController
# GET /articles
# GET /articles.json
def index
@articles = Article.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @articles }
end
end
# GET /articles/1
# GET /articles/1.json
def show
@article = Article.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @article }
end
end
# GET /articles/new
# GET /articles/new.json
def new
@article = Article.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @article }
end
end
# GET /articles/1/edit
def edit
@article = Article.find(params[:id])
end
# POST /articles
# POST /articles.json
def create
@article = Article.new(params[:article])
respond_to do |format|
if @article.save
format.html { redirect_to @article, notice: 'Article was successfully created.' }
format.json { render json: @article, status: :created, location: @article }
else
format.html { render action: "new" }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
end
# PUT /articles/1
# PUT /articles/1.json
def update
@article = Article.find(params[:id])
respond_to do |format|
if @article.update_attributes(params[:article])
format.html { redirect_to @article, notice: 'Article was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
end
# DELETE /articles/1
# DELETE /articles/1.json
def destroy
@article = Article.find(params[:id])
@article.destroy
respond_to do |format|
format.html { redirect_to articles_url }
format.json { head :no_content }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment