segment.user_id = @user.id
- a = Node.find(segment.node_a.to_i)
- b = Node.find(segment.node_b.to_i)
+ segment.from_node = Node.find(segment.node_a.to_i)
+ segment.to_node = Node.find(segment.node_b.to_i)
- unless a and a.visible and b and b.visible
- render :nothing => true, :status => 400
+ unless segment.precondtions_ok? # are the nodes visible?
+ render :nothing => true, :status => 412
end
if segment.save_with_history
if way
way.user_id = @user.id
+ unless way.precondtions_ok? # are the segments (and their nodes) visible?
+ render :nothing => true, :status => 412
+ return
+ end
+
if way.save_with_history
render :text => way.id
+ return
else
render :nothing => true, :status => 500
+ return
end
return
else
way = Way.find(params[:id])
case request.method
-
+
when :get
unless way.visible
render :nothing => true, :status => 410
validates_numericality_of :node_a
validates_numericality_of :node_b
- # FIXME validate a nd b exist and are visible
has_many :old_segments, :foreign_key => :id
belongs_to :user
+ has_one :from_node, :class => 'Node', :foreign_key => 'node_a'
+ has_one :to_node, :class => 'Node', :foreign_key => 'node_b'
def self.from_xml(xml, create=false)
p = XML::Parser.new
end
end
+ def precondtions_ok?
+ return from_node and from_node.visible and to_node and to_node.visible
+ end
end
old_way.save_with_dependencies
end
+ def preconditions_ok?
+ self.segs.each do |n|
+ segment = Segment.find(n)
+ unless segment and segment.visible and segment.preconditions_ok?
+ return false
+ end
+ end
+ return true
+ end
+
end