Skip to content

Commit ce9615d

Browse files
committed
Adding first iteration of programs
1 parent bd872b8 commit ce9615d

6 files changed

Lines changed: 47 additions & 3 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class ProgramsController < InheritedController
2+
load_and_authorize_resource
3+
belongs_to :user, :optional => true
4+
5+
def show
6+
@program = Program.find_by_slug(params[:slug])
7+
show!
8+
end
9+
10+
respond_to :html, :only => [:index, :show]
11+
end

app/models/program.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ class Program
66
key :title, String
77
key :source_code, String
88

9+
def to_param
10+
slug
11+
end
12+
913
end

app/views/programs/index.html.haml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
%h1 Every Awesome Program We've Got
2+
3+
Here's the motherload! Check out these great programs everybody has made!
4+
5+
%h2 The Super Sweet List
6+
7+
We've picked out a few extra-awesome ones for your enjoyment.
8+
9+
%ul
10+
%li Foo
11+
%li Foo
12+
%li Foo
13+
%li Foo
14+
%li Foo
15+
16+
%h2 Other Great Programs
17+
18+
Here it is: every single program we've got. Check them out!
19+
20+
%ul
21+
- @programs.each do |program|
22+
%li= link_to program.title, program_path(program.author_username, program)

app/views/programs/show.html.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
%h1 #{@program.title}, by #{@program.author_username}
2+
3+
%code
4+
= @program.source_code
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
= semantic_menu :class => "nav" do |root|
2-
- root.add "Questions", questions_path
2+
- root.add "Questions", questions_path
3+
- root.add "Programs", programs_path

config/routes.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
HacketyHackCom::Application.routes.draw do
22

3-
43
resources :questions do
54
resources :answers
65
end
76

7+
resources :programs, :only => [:index]
88

99
constraints(ApiConstraint) do
1010
match '/' => 'static#api_root'
@@ -26,7 +26,9 @@
2626
match 'users/:id/followers', :controller => 'users', :action => 'followers'
2727
match 'users/:id/follow', :controller => 'users', :action => 'follow'
2828
match 'users/:id/unfollow', :controller => 'users', :action => 'unfollow'
29-
29+
3030
root :to => "static#root"
3131

32+
match ':user_id/:slug', :to => "programs#show", :as => :program
33+
3234
end

0 commit comments

Comments
 (0)