Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to create an Ember.js app where in the model, I load in a JSON as an object. (Just to display for now.)

Here is my rails schema:

  create_table "recipes", force: true do |t|
    t.integer "recipe_id"
    t.integer "version"
    t.string  "author"
    t.json    "recipe"
    t.json    "steps"
    t.integer "parent_id"
 end

And the serializer in ember:

class ProtocolSerializer < ActiveModel::Lead
    attributes :recipe_id, :version, :author, :recipe, :steps, :parent_id
end

What is the proper way to make the model? This is the best that I got, but I am not sure how to import the json properly. A string would be fine if that is easier:

App.Protocol = DS.Model.extend
  recipe_id: DS.attr('int')
  version: DS.attr('int')
  author: DS.attr('string')
  recipe: DS.attr('string')
  steps: DS.attr('string')
  parent_id: DS.attr('int')

Thanks so much!

EDIT: I think I figured it out- importing json as a string works just fine except it removes the '{ }' from the final web page. Instead of 'int' I should have used 'number'.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.