File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11class QuestionsController < InheritedController
2- before_filter :set_support
32 load_and_authorize_resource
3+ prepend_before_filter :set_presenter
4+ prepend_before_filter :set_support
45
56 def create
67 @question = Question . create params [ :question ]
@@ -18,22 +19,31 @@ def update
1819 end
1920
2021 def collection
21- if @support
22- @questions ||= end_of_association_chain . supports . newest_first . paginate ( :page => params [ :page ] )
23- else
24- @questions ||= end_of_association_chain . no_supports . newest_first . paginate ( :page => params [ :page ] )
25- end
22+ @questions = @presenter . apply_scope ( end_of_association_chain ) . newest_first . paginate ( :page => params [ :page ] )
2623 end
27-
24+
2825 def collection_url
29- @support ? support_questions_path : questions_path
26+ collection_path
3027 end
28+
29+ def collection_path
30+ @presenter . collection_path
31+ end
32+
3133 def new_resource_path
32- @support ? new_support_question_path : new_question_path
34+ @presenter . new_resource_path
35+ end
36+
37+ def resource_url ( *params )
38+ resource_path ( params )
3339 end
3440
35- def resource_path ( *resource )
36- @support ? support_question_path ( *resource ) : question_path ( *resource )
41+ def resource_path ( *other )
42+ if other [ 0 ]
43+ @presenter . resource_path ( other )
44+ else
45+ @presenter . resource_path ( resource )
46+ end
3747 end
3848
3949 def edit_resource_path
@@ -47,4 +57,12 @@ def set_support
4757 end
4858 end
4959
60+ def set_presenter
61+ if @support
62+ @presenter = SupportPresenter . new ( resource )
63+ else
64+ @presenter = QuestionPresenter . new ( resource )
65+ end
66+ end
67+
5068end
Original file line number Diff line number Diff line change 1+ class QuestionPresenter
2+ include Rails . application . routes . url_helpers
3+
4+ def initialize ( q )
5+ @question = q
6+ end
7+
8+ def resource_path ( question )
9+ if question
10+ question_path ( question )
11+ else
12+ question_path ( @question )
13+ end
14+ end
15+
16+ def new_resource_path
17+ new_question_path
18+ end
19+
20+ def collection_path
21+ questions_path
22+ end
23+
24+ def edit_resource_path
25+ edit_question_path
26+ end
27+
28+ def apply_scope ( chain )
29+ chain . no_supports
30+ end
31+
32+ def answers_path
33+ question_answer_path ( @question )
34+ end
35+ end
Original file line number Diff line number Diff line change 1+ class SupportPresenter
2+ include Rails . application . routes . url_helpers
3+
4+ def initialize ( sq )
5+ @support_question = sq
6+ end
7+
8+ def page_title
9+ "Support Questions"
10+ end
11+
12+ def new_resource_path
13+ new_support_question_path
14+ end
15+
16+ def collection_path
17+ support_questions_path
18+ end
19+
20+ def edit_resource_path
21+ edit_support_question_path
22+ end
23+
24+ def resource_path ( question )
25+ if question
26+ support_question_path ( question )
27+ else
28+ support_question_path ( @question )
29+ end
30+ end
31+
32+ def apply_scope ( chain )
33+ chain . supports
34+ end
35+ end
Original file line number Diff line number Diff line change 1- - curr_module = @support ? '/support' : ''
2- = simple_form_for(resource, :url => curr_module.concat(@form_url)) do |f|
1+ = simple_form_for(resource, :url => @form_url) do |f|
32 = f.error_notification
43
54 .inputs
Original file line number Diff line number Diff line change 22 %h2 Have A Question?
33 %p Ask away! No question is too big or too small.
44 - if current_user
5- = link_to " Ask a Question" , new_question_path , :class => " btn success"
5+ = link_to " Ask a Question" , new_resource_path , :class => " btn success"
66 - else
77 %p Log in to ask a question
88 = link_to " Log In" , login_path, :class => " btn success"
You can’t perform that action at this time.
0 commit comments