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
23 load_and_authorize_resource
34
45 def create
@@ -17,6 +18,33 @@ def update
1718 end
1819
1920 def collection
20- @questions ||= end_of_association_chain . newest_first . paginate ( :page => params [ :page ] )
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
2126 end
27+
28+ def collection_url
29+ @support ? support_questions_path : questions_path
30+ end
31+ def new_resource_path
32+ @support ? new_support_question_path : new_question_path
33+ end
34+
35+ def resource_path ( *resource )
36+ @support ? support_question_path ( *resource ) : question_path ( *resource )
37+ end
38+
39+ def edit_resource_path
40+ @support ? edit_support_question_path : edit_question_path
41+ end
42+
43+ def set_support
44+ @support = request . env [ 'PATH_INFO' ] . include? ( 'support' )
45+ if @support && params [ :question ]
46+ params [ :question ] [ :support ] = true
47+ end
48+ end
49+
2250end
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ class Question
44 key :title , String
55 key :description , String
66 key :solution_id , ObjectId
7+ key :support , Boolean
78 timestamps!
89
910 belongs_to :user
@@ -12,5 +13,6 @@ class Question
1213 validates_presence_of :title , :description
1314
1415 scope :newest_first , sort ( :created_at . desc )
15-
16+ scope :supports , where ( :support => true )
17+ scope :no_supports , where ( :support => nil )
1618end
Original file line number Diff line number Diff line change 1- = simple_form_for(resource, :url => @form_url) do |f|
1+ - curr_module = @support ? '/support' : ''
2+ = simple_form_for(resource, :url => curr_module.concat(@form_url)) do |f|
23 = f.error_notification
34
45 .inputs
Original file line number Diff line number Diff line change 11- content_for :title do
2- Questions
2+ -if @support
3+ Support Questions
4+ -else
5+ Questions
36
47- content_for :sidebar do
58 - if can? :create, Question
69 %section .ask
710 = link_to " Ask a Question" , new_resource_path, :class => " btn success"
8-
9- %section .support
10- %h2 Support
11- %p Having a problem running Hackety Hack? Found a bug? Check out our #{link_to "support section", "" }.
11+ - unless @support
12+ %section .support
13+ %h2 Support
14+ %p Having a problem running Hackety Hack? Found a bug? Check out our #{link_to "support section", support_questions_path }.
1215
1316
1417%ul .questions
Original file line number Diff line number Diff line change 33 - root.add " Questions" , questions_path
44 - root.add " Programs" , programs_path
55 - root.add " FAQ" , faq_path
6+ - root.add " Support" , support_questions_path
7+
Original file line number Diff line number Diff line change 22 - root.add " Questions" , questions_path
33 - root.add " Programs" , programs_path
44 - root.add " FAQ" , faq_path
5+ - root.add " Support" , support_questions_path
Original file line number Diff line number Diff line change 33 resources :questions do
44 resources :answers
55 end
6-
6+
7+ scope '/support' , :as => 'support' do
8+ resources :questions , :controller => 'questions'
9+ end
10+
711 resources :programs , :only => [ :index , :show ]
812
913 constraints ( ApiConstraint ) do
You can’t perform that action at this time.
0 commit comments