Skip to content

Instantly share code, notes, and snippets.

@Sephi-Chan
Created March 16, 2012 20:45
Show Gist options
  • Save Sephi-Chan/2052566 to your computer and use it in GitHub Desktop.
Save Sephi-Chan/2052566 to your computer and use it in GitHub Desktop.
class TopicsController < ApplicationController
def index
@topics = Topic.all
end
def show
@topic = Topic.find(params[:id])
end
def new
@topic = Topic.new
end
def create
@topic = Topic.new(params[:topic])
if @topic.save
@topic = Topic.new(:name => params[:topic][:name], :last_poster_id => current_user.id, :last_post_at => Time.now, :forum_id => params[:topic][:forum_id])
if @topic.save
flash[:notice] = "Successfully created topic."
redirect_to "/forums/#{@topic.forum_id}"
else
redirect :action => 'new'
end
else
render :action => 'new'
end
end
def edit
@topic = Topic.find(params[:id])
end
def update
@topic = Topic.find(params[:id])
if @topic.update_attributes(params[:topic])
redirect_to @topic, :notice => "Successfully updated topic."
else
render :action => 'edit'
end
end
def destroy
@topic = Topic.find(params[:id])
@topic.destroy
redirect_to topics_url, :notice => "Successfully destroyed topic."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment