/
questions_controller.rb
68 lines (55 loc) · 1.44 KB
/
questions_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class QuestionsController < InheritedController
load_and_authorize_resource
prepend_before_filter :set_presenter
prepend_before_filter :set_support
def create
@question = Question.create params[:question]
@question.user = current_user
create!(:notice => "Question Asked!") { collection_url }
end
def show
@answer = Answer.new
show!
end
def update
params[:question][:solution_id] != @question.solution_id ? update!(:notice => "Okay! We've selected that answer") : update!
end
def collection
@questions = @presenter.apply_scope(end_of_association_chain).newest_first.paginate(:page => params[:page])
end
def collection_url
collection_path
end
def collection_path
@presenter.collection_path
end
def new_resource_path
@presenter.new_resource_path
end
def resource_url(*params)
resource_path(params)
end
def resource_path(*other)
if other[0]
@presenter.resource_path(other)
else
@presenter.resource_path(resource)
end
end
def edit_resource_path
@support ? edit_support_question_path : edit_question_path
end
def set_support
@support = request.env['PATH_INFO'].include?('support')
if @support && params[:question]
params[:question][:support] = true
end
end
def set_presenter
if @support
@presenter = SupportPresenter.new(resource)
else
@presenter = QuestionPresenter.new(resource)
end
end
end