dimanche 27 janvier 2019

How do I display data from Rails backend to Ember frontend without saving it in the database and without using Ember-Data?

The problem:

I have used rest-client to pull news articles from newsapi.org through my Rails backend. I can display that data on localhost:3000/articles. I do not (necessarily) want to save this data to a database and would like to simply display it on my Ember frontend after calling it on my Rails backend. I get this error:

Error while processing route: article Assertion Failed: You must include an 'id' for article in an object passed to 'push'  

I understand this to mean that my data has no 'id' - which it doesn't. I have no control over the data coming in.

{
  "status": "ok",
  "totalResults": 6868,
  "articles": [
{
  "source": {
    "id": "mashable",
    "name": "Mashable"
  },
  "author": "Lacey Smith",
  "title": "Cannabis may alter the genetic makeup of sperm",
  "description": "A new study suggests that marijuana use can not 
only lower sperm count, but also affect sperm DNA. Read more... More 
about Marijuana, Cannabis, Sperm, Science, and Health",
  "url": "https://mashable.com/video/cannabis-sperm-dna/",
  "content": null
},  

Ember-Data doesn't like this because it's not in JSONAPI format and I can't change it to JSONAPI. How do I display this data on my ember frontend without using Ember-Data and without having to save it into my database? The tutorials I've found all have examples using databases and Ember-Data.

What I've already tried:

I tried to save it to my database and load from there, but I'm thinking that might complicate the idea, since I would need to scrape the data and save it to my database and that has proven difficult to do. I'm not experienced with backend stuff and haven't found many answers. If you have an answer for doing it this way, feel free to answer here:

How to automatically save data from url to database

I'm willing to try it out. I thought originally this would be the best way to go. I could save the data and only add to the database when new articles were returned. I'm not having any luck this way, so I thought I'd approach it from another direction.

Thanks for any help!




Aucun commentaire:

Enregistrer un commentaire