Created
March 16, 2012 20:45
-
-
Save Sephi-Chan/2052566 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 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