]> git.openstreetmap.org Git - rails.git/commitdiff
Include a user URL in JSON and XML responses
authorTom Hughes <tom@compton.nu>
Sun, 2 Dec 2012 16:38:59 +0000 (16:38 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 3 Dec 2012 14:50:54 +0000 (14:50 +0000)
app/views/notes/_note.json.jsonify
app/views/notes/_note.xml.builder

index ce9ddb4bfc8c6a122355baeac9fe97c02f7e905b..5724dfd540fc0392d101544e2079927c4e358b23 100644 (file)
@@ -2,7 +2,7 @@ json.type "Feature"
 
 json.geometry do
   json.type "Point"
-  json.coordinates [ note.lon, note.lat ]              
+  json.coordinates [ note.lon, note.lat ]
 end
 
 json.properties do
@@ -16,8 +16,13 @@ json.properties do
 
   json.comments(note.comments) do |comment|
     json.date comment.created_at
-    json.uid comment.author.id unless comment.author.nil?
-    json.user comment.author.display_name unless comment.author.nil?
+
+    if comment.author
+      json.uid comment.author.id
+      json.user comment.author.display_name
+      json.user_url user_url(:display_name => comment.author.display_name)
+    end
+
     json.action comment.event
     json.text comment.body unless comment.body.nil?
   end
index 1877726769a968f78c74c07ca0dd803081239ef3..7e4585f86fbacaf37498337ab48a7d2c2d5dac9f 100644 (file)
@@ -2,7 +2,7 @@ xml.note("lon" => note.lon, "lat" => note.lat) do
   xml.id note.id
   xml.url note_url(note, :format => params[:format])
   xml.comment_url comment_note_url(note, :format => params[:format])
-  xml.close_url close_note_url(note, :format => params[:format])  
+  xml.close_url close_note_url(note, :format => params[:format])
   xml.date_created note.created_at
   xml.status note.status
 
@@ -14,10 +14,15 @@ xml.note("lon" => note.lon, "lat" => note.lat) do
     note.comments.each do |comment|
       xml.comment do
         xml.date comment.created_at
-        xml.uid comment.author.id unless comment.author.nil?
-        xml.user comment.author.display_name unless comment.author.nil?
+
+        if comment.author
+          xml.uid comment.author.id
+          xml.user comment.author.display_name
+          xml.user_url user_url(:display_name => comment.author.display_name)
+        end
+
         xml.text comment.body
-      end      
+      end
     end
   end
 end