Skip to content

Commit ae22766

Browse files
committed
updated to save programs
1 parent 8b70580 commit ae22766

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

app/controllers/programs_controller.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
class ProgramsController < ApplicationController
2+
prepend_around_filter ApiAuthorizedFilter.new
3+
4+
#ugly, but here until i can inspect the issue...
5+
protect_from_forgery :except => :create
6+
27
def index
3-
@programs = Program.all
8+
@programs = Program.find(:all, :conditions => ["user_id == ?", current_user.id])
9+
respond_to do |format|
10+
format.html
11+
format.yaml {require 'yaml'; render :text => (Hash.from_xml(@programs.to_xml)).to_yaml}
12+
end
413
end
514

615
def show

app/controllers/users_controller.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
class UsersController < ApplicationController
22

3+
prepend_around_filter ApiAuthorizedFilter.new
4+
5+
#ugly, but here until i can inspect the issue...
6+
protect_from_forgery :except => :programs
7+
38
def new
49
@user = User.new
510
end
@@ -34,4 +39,19 @@ def update
3439
def show
3540
@user = User.find_by_username(params[:username])
3641
end
42+
43+
def programs
44+
render false if current_user.username != params[:username]
45+
@program = Program.find_by_name(params[:name].gsub(/_/, " "))
46+
if @program.nil?
47+
@program = Program.new
48+
@program.user = current_user
49+
end
50+
@program.name = params[:name]
51+
@program.text = params[:text]
52+
@program.save
53+
54+
require 'yaml'; render :text => (Hash.from_xml(@program.to_xml)).to_yaml
55+
end
56+
3757
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717
map.resources :watchings
1818
map.resources :comments
1919

20+
map.save_program "/users/:username/programs/:name", :controller => "users", :action => "programs"
21+
2022
end

0 commit comments

Comments
 (0)