Skip to content

Instantly share code, notes, and snippets.

@kracekumar
Created March 22, 2011 15:38
Show Gist options
  • Save kracekumar/881430 to your computer and use it in GitHub Desktop.
Save kracekumar/881430 to your computer and use it in GitHub Desktop.
class ForumTopicsController < ApplicationController
before_filter :login_required
filter_access_to:all
def add
@forum=ForumTopics.new(params[:forum])
@forum.author=current_user
if request.post? and @forum.save
flash[:notice] = 'Forum Topic Added'
redirect_to :controller => 'forum_topics', :action => 'view', :id =>@forum_topics
end
end
def add_comment
@cmnt= ForumTopicReply.new(params[:comment])
@cmnt.author= current_user
@cmnt.save
end
def all
@forum=ForumTopics.paginate :page=> params[:page]
end
def delete
@forum_topics=ForumTopics.find(params[:id]).destroy
flash[:notice] = 'Forum Topic deleted successfully'
redirect_to :controller => 'forum_topic' ,:action=>'index'
end
def delete_comment
@comment=ForumTopicReply.find(params[:id])
ForumTopicReply.destroy(params[:id])
end
def edit
@forum=ForumTopics.find(params[:id])
if request.post? and @forum.update_attributes(params[:topic])
flash[:notice] = 'Forum Topic content Updated'
redirect_to :controller => 'forum_topics', :action =>'view', :id =>@forum.id
end
end
def index
@current_user =current_user
@forum = []
if request.get?
@forum=ForumTopics.title_like_all params[:query].split unless params[:query].nil?
end
end
def search_forum_topics_ajax
@forum=nil
conditions = ["title LIKE ?", "#{params[:query]}%"]
@forum=ForumTopics.find(:all, :conditions => conditions) unless params[:query] == ''
render :layout => false
end
def view
@current_user=current_user
@forum=ForumTopics.find(params[:id])
@comments=@forum.comments
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment