-
-
Save dansimpson/615565 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
class ConversationsController < ApplicationController | |
before_filter :load_board | |
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(params[:comment]) | |
@conversation.user_id = @comment.user_id = current_user.id | |
respond_to do |format| | |
if @conversation.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 | |
private | |
def load_board | |
@board = Board.find(params[:board_id]) | |
unless @board | |
#redirect or do something | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment