]> git.openstreetmap.org Git - rails.git/blob - app/controllers/way_controller.rb
openlayers madness
[rails.git] / app / controllers / way_controller.rb
1 class WayController < ApplicationController
2   require 'xml/libxml'
3
4   before_filter :authorize
5
6   def create
7     if request.put?
8       way = Way.from_xml(request.raw_post, true)
9
10       if way
11         way.user_id = @user.id
12         if way.save_with_history
13
14
15           render :text => way.id
16         else
17           render :nothing => true, :status => 500
18         end
19         return
20       else
21         render :nothing => true, :status => 400 # if we got here the doc didnt parse
22         return
23       end
24     end
25
26     render :nothing => true, :status => 500 # something went very wrong
27   end
28
29   def rest
30     unless Way.exists?(params[:id])
31       render :nothing => true, :status => 404
32       return
33     end
34
35     way = Way.find(params[:id])
36     case request.method
37    
38     when :get
39       unless way.visible
40         render :nothing => true, :status => 410
41         return
42       end
43       render :text => way.to_xml.to_s
44
45     when :delete
46       unless way.visible
47         render :nothing => true, :status => 410
48         return
49       end
50
51       way.visible = false
52       way.save_with_history
53
54     end
55  
56   end
57
58 end