Skip to content

Commit 7f3f73f

Browse files
committed
Merge pull request #87 from abhirao/support
Support section
2 parents 453bd5a + 1a29a3c commit 7f3f73f

7 files changed

Lines changed: 50 additions & 9 deletions

File tree

app/controllers/questions_controller.rb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class 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+
2250
end

app/models/question.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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)
1618
end

app/views/questions/_form.html.haml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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

app/views/questions/index.html.haml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
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

app/views/shared/menu/_footer.html.haml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
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+

app/views/shared/menu/_main.html.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
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

config/routes.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
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

0 commit comments

Comments
 (0)