Skip to content

Instantly share code, notes, and snippets.

@baileylo
Created October 7, 2010 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save baileylo/615558 to your computer and use it in GitHub Desktop.
Save baileylo/615558 to your computer and use it in GitHub Desktop.
class ConversationsController < ApplicationController
# GET /conversations
# GET /conversations.xml
def index
@conversations = Conversation.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @conversations }
end
end
# GET /conversations/1
# GET /conversations/1.xml
def show
@conversation = Conversation.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @conversation }
end
end
# GET /conversations/new
# GET /conversations/new.xml
def new
@conversation = Conversation.new
@comment = @conversation.comments.build
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @conversation }
end
end
# GET /conversations/1/edit
def edit
@conversation = Conversation.find(params[:id])
end
# POST /conversations
# POST /conversations.xml
def create
@conversation = Conversation.new(params[:conversation])
@comment = @conversation.comments.build
@comment.body = params[:body]
@comment.user_id = current_user.id
logger.debug 'lgaon longa longa logan' +@comment.body
respond_to do |format|
if @conversation.save && $comment.save
format.html { redirect_to(@conversation, :notice => 'Conversation was successfully created.') }
format.xml { render :xml => @conversation, :status => :created, :location => @conversation }
else
format.html { render :action => "new" }
format.xml { render :xml => @conversation.errors, :status => :unprocessable_entity }
end
end
end
# PUT /conversations/1
# PUT /conversations/1.xml
def update
@conversation = Conversation.find(params[:id])
respond_to do |format|
if @conversation.update_attributes(params[:conversation])
format.html { redirect_to(@conversation, :notice => 'Conversation was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @conversation.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /conversations/1
# DELETE /conversations/1.xml
def destroy
@conversation = Conversation.find(params[:id])
@conversation.destroy
respond_to do |format|
format.html { redirect_to(conversations_url) }
format.xml { head :ok }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment