Skip to content

Commit 116e2d3

Browse files
committed
pretty routes
1 parent 81a5547 commit 116e2d3

4 files changed

Lines changed: 29 additions & 2 deletions

File tree

app/controllers/programs_controller.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@ class ProgramsController < InheritedController
22
load_and_authorize_resource
33

44
belongs_to :user, :optional => true
5-
65
respond_to :html, :only => [:index, :show]
6+
7+
def show
8+
# @program = Program.find_by_slug(params[:slug])
9+
show!
10+
end
11+
12+
#################
13+
14+
def begin_of_association_chain
15+
if params[:user_id]
16+
@user = User.find_by_username params[:user_id]
17+
@user
18+
end
19+
end
20+
21+
def resource
22+
@program ||= end_of_association_chain.find_by_slug(params[:id])
23+
end
24+
725
end

app/controllers/users_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@ def followers
3030
@user = User.first(:id => params[:user_id])
3131
end
3232

33+
#################
34+
35+
def resource
36+
@user ||= end_of_association_chain.find_by_username(params[:id])
37+
end
3338

3439
end

app/models/user.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class User
1212
many :questions
1313
many :answers
1414

15+
def to_param
16+
self.username
17+
end
18+
1519
def programs
1620
Program.by_username self.username
1721
end

app/views/programs/index.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ Here it is: every single program we've got. Check them out!
2727
%ul
2828
- collection.each do |program|
2929
- user = User.find_by_username(program.author_username)
30-
%li #{link_to program.title, user_program_path(user, program.id)}, by #{link_to user.username, user}
30+
%li #{link_to program.title, user_program_path(user, program)}, by #{link_to user.username, user}

0 commit comments

Comments
 (0)