Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalids IDs in JSON #117

Open
Rudloff opened this issue Feb 7, 2017 · 1 comment
Open

Invalids IDs in JSON #117

Rudloff opened this issue Feb 7, 2017 · 1 comment

Comments

@Rudloff
Copy link

Rudloff commented Feb 7, 2017

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants