Class: Sechat::QuestionsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/sechat/controllers/questions_controller.rb

Instance Method Summary collapse

Instance Method Details

#build_question(params = nil) ⇒ Object



52
53
54
# File 'lib/sechat/controllers/questions_controller.rb', line 52

def build_question(params = nil)
  resource_class.new(params)
end

#createObject



30
31
32
33
34
# File 'lib/sechat/controllers/questions_controller.rb', line 30

def create
  @question = build_question(params[:question])
  @question.save
  respond_with(@question, :location => { :action => 'show', :id => @question.to_param })
end

#destroyObject



42
43
44
45
46
# File 'lib/sechat/controllers/questions_controller.rb', line 42

def destroy
  @question = resource_class.find(params[:id])
  @question.destroy
  respond_with(@question, :location => { :action => 'index' })
end

#editObject



26
27
28
# File 'lib/sechat/controllers/questions_controller.rb', line 26

def edit
  @question = resource_class.find(params[:id])
end

#indexObject



3
4
5
6
# File 'lib/sechat/controllers/questions_controller.rb', line 3

def index
  @questions = resource_class.latest
  respond_with(@questions)
end

#newObject



21
22
23
24
# File 'lib/sechat/controllers/questions_controller.rb', line 21

def new
  @question = build_question
  respond_with(@question)
end

#resource_classObject



48
49
50
# File 'lib/sechat/controllers/questions_controller.rb', line 48

def resource_class
  Question
end

#showObject



16
17
18
19
# File 'lib/sechat/controllers/questions_controller.rb', line 16

def show
  @question = resource_class.find(params[:id])
  respond_with(@question)
end

#unansweredObject



8
9
10
11
12
13
14
# File 'lib/sechat/controllers/questions_controller.rb', line 8

def unanswered
  @questions = resource_class.unanswered.latest
  
  respond_with(@questions) do |format|
    format.html { render 'index' }
  end
end

#updateObject



36
37
38
39
40
# File 'lib/sechat/controllers/questions_controller.rb', line 36

def update
  @question = resource_class.find(params[:id])
  @question.update_attributes(params[:question])
  respond_with(@question, :location => { :action => 'show', :id => @question.to_param })
end