voxe / voxe-web

Voxe.org is a non-partisan tool that compares and contextualizes political platforms. Citizens, media and startups can reuse this open platform designed to held forge an informed electorate.
http://voxe.org
Apache License 2.0
17 stars 9 forks source link

Invalids IDs in JSON #117

Open Rudloff opened 7 years ago

Rudloff commented 7 years ago

Hello,

I'm trying to run your app with ruby 2.1.5p273 and MongoDB 2.4.10 on Debian 8.7.

I get a lot of JS errors because object IDs are incorrectly converted to JSON:

{
  "meta": {
    "code": 200
  },
  "response": {
    "election": {
      "id": {
        "raw_data": "X�\\u000f�:@&��\\u0000\\u0000\\u0001"
      },
      "name": "Election Presidentielle France 2007",
      "namespace": "france-presidentielle-2007",
      "published": true,
      "date": null
    }
  }
}

Which leads to things like this:

<div election-id="[object Object]" class="election">

Doing something like this seems to fix the JSON:

diff --git a/app/views/api/v1/elections/search.json.rabl b/app/views/api/v1/elections/search.json.rabl
index 869abc1..8e8c417 100644
--- a/app/views/api/v1/elections/search.json.rabl
+++ b/app/views/api/v1/elections/search.json.rabl
@@ -1,6 +1,9 @@
 object false
 collection @elections => :elections
-attributes :id, :name, :namespace, :published, :date
+attributes :name, :namespace, :published, :date
+node :id do |election|
+    election.id.to_s()
+end
 child (@only_published_candidacies ? :published_candidacies_sorted : :candidacies_sorted) do
   extends "api/v1/candidacies/base"
 end
diff --git a/app/views/api/v1/elections/show.json.rabl b/app/views/api/v1/elections/show.json.rabl
index a50c865..ce4a750 100644
--- a/app/views/api/v1/elections/show.json.rabl
+++ b/app/views/api/v1/elections/show.json.rabl
@@ -1,6 +1,9 @@
 object false
 child @election do
-  attributes :id, :name, :namespace, :path, :published, :date
+  attributes :name, :namespace, :path, :published, :date
+  node :id do |election|
+      election.id.to_s()
+  end
   # child :parent_election => :parentElection do
   #   attributes :id, :name
   # end
barodeur commented 7 years ago

Hi @Rudloff, this is Paul, we might have meet in Strasbourg, I was intern at Novelys with @yannski long time ago. I'm also maintainer for this project.

I'm going to send a pull request for this in a few minutes.