File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121 haml :"programs/show"
2222end
2323
24+ put "/programs/:username/:slug.json" do
25+ require_login_or_api! :username => params [ :username ] , :password => params [ :password ]
26+ if current_user . username != params [ :username ]
27+ redirect "/"
28+ end
29+ program = Program . first ( :creator_username => params [ :username ] , :slug => params [ :slug ] )
30+ if program . nil?
31+ program = Program . create ( params )
32+ else
33+ program . update_attributes ( params )
34+ program . save
35+ end
36+
37+ flash [ :notice ] = "Program updated!"
38+ redirect "/programs/#{ program . creator_username } /#{ program . slug } "
39+ end
40+
2441put "/programs/:username/:slug" do
2542 require_login_or_api! :username => params [ :username ] , :password => params [ :password ]
2643 if current_user . username != params [ :username ]
2744 flash [ :notice ] = "Sorry, buddy"
28- redirect_to "/"
45+ redirect "/"
2946 end
3047 program = Program . first ( :creator_username => params [ :username ] , :slug => params [ :slug ] )
3148 program . update_attributes ( params [ :program ] )
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ class Program
33 key :creator_username , String
44 key :title , String
55 key :slug , String
6+ key :code , String
67
78 validate_on_create :slug_check
89 before_save :make_slug
Original file line number Diff line number Diff line change @@ -14,6 +14,6 @@ def require_directory dirname
1414
1515class String
1616 def to_slug
17- self . gsub ( /\s / , "_" ) . downcase
17+ self . gsub ( /\W / , "" ) . gsub ( / \ s /, "_" ) . downcase
1818 end
1919end
Original file line number Diff line number Diff line change 11%h1 = @program.title
22%h2 By #{@program.creator_username}
33
4- %p = @program.body
4+ %p = @program.code
You can’t perform that action at this time.
0 commit comments