Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convert messages controller to return HTML and JSON instead of HTML a…

…nd XML.
  • Loading branch information...
commit d73096065ea59dca42683b599133eebdbd20e259 1 parent 67d6764
@sarahmei authored
Showing with 14 additions and 14 deletions.
  1. +14 −14 app/controllers/messages_controller.rb
View
28 app/controllers/messages_controller.rb
@@ -1,34 +1,34 @@
class MessagesController < ApplicationController
# GET /messages
- # GET /messages.xml
+ # GET /messages.json
def index
@messages = Message.all
respond_to do |format|
format.html # index.html.erb
- format.xml { render :xml => @messages }
+ format.json { render :json => @messages }
end
end
# GET /messages/1
- # GET /messages/1.xml
+ # GET /messages/1.json
def show
@message = Message.find(params[:id])
respond_to do |format|
format.html # show.html.erb
- format.xml { render :xml => @message }
+ format.json { render :json => @message }
end
end
# GET /messages/new
- # GET /messages/new.xml
+ # GET /messages/new.json
def new
@message = Message.new
respond_to do |format|
format.html # new.html.erb
- format.xml { render :xml => @message }
+ format.json { render :json => @message }
end
end
@@ -38,46 +38,46 @@ def edit
end
# POST /messages
- # POST /messages.xml
+ # POST /messages.json
def create
@message = Message.new(params[:message])
respond_to do |format|
if @message.save
format.html { redirect_to(@message, :notice => 'Message was successfully created.') }
- format.xml { render :xml => @message, :status => :created, :location => @message }
+ format.json { render :json => @message, :status => :created, :location => @message }
else
format.html { render :action => "new" }
- format.xml { render :xml => @message.errors, :status => :unprocessable_entity }
+ format.json { render :json => @message.errors, :status => :unprocessable_entity }
end
end
end
# PUT /messages/1
- # PUT /messages/1.xml
+ # PUT /messages/1.json
def update
@message = Message.find(params[:id])
respond_to do |format|
if @message.update_attributes(params[:message])
format.html { redirect_to(@message, :notice => 'Message was successfully updated.') }
- format.xml { head :ok }
+ format.json { head :ok }
else
format.html { render :action => "edit" }
- format.xml { render :xml => @message.errors, :status => :unprocessable_entity }
+ format.json { render :json => @message.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /messages/1
- # DELETE /messages/1.xml
+ # DELETE /messages/1.json
def destroy
@message = Message.find(params[:id])
@message.destroy
respond_to do |format|
format.html { redirect_to(messages_url) }
- format.xml { head :ok }
+ format.json { head :ok }
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.