Class: Qa::TopicsController

Inherits:
QaController
  • Object
show all
Defined in:
app/controllers/qa/topics_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



11
12
13
14
15
16
17
# File 'app/controllers/qa/topics_controller.rb', line 11

def create
  (render :nothing => true; return false) if (params[:title].blank? || params[:content].blank?)

  @topic = QATopic.create(default_data.merge(:title => params[:title], :category_id => params[:category_id]))

  fetch_topic_list
end

#destroyObject



31
32
# File 'app/controllers/qa/topics_controller.rb', line 31

def destroy
end

#indexObject



5
6
7
8
9
# File 'app/controllers/qa/topics_controller.rb', line 5

def index
  @qa_options = {:category_id => params[:category_id]}

  fetch_topic_list
end

#new_topics_countObject



34
35
36
37
38
39
40
# File 'app/controllers/qa/topics_controller.rb', line 34

def new_topics_count
  @new_topcis_count = QATopic.where(:category_id => params[:category_id]).where("created_at >= ?", Time.at(params[:time_begin].to_i)).count

  respond_to do |format|
    format.json { render :json => {:new_topcis_count => @new_topcis_count}, :status => 200 }
  end
end

#showObject



19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/qa/topics_controller.rb', line 19

def show
  @topic = QATopic.find(params[:id])
  QATopic.increment_counter :view_count, @topic.id
  @topic.view_count += 1
  @topic.content = @topic._content_markdown_cache
  @replies = @topic.replies.map {|reply| reply.content = reply._content_markdown_cache; reply }

  respond_to do |format|
    format.json { render :json => {:topic => @topic, :replies => @replies}, :status => 200}
  end
end