通过rails将一个json对象从postgres加载到ember-data中?

时间:2014-08-04 00:42:55

标签: ruby-on-rails json postgresql ember.js ember-data

我正在尝试创建一个Ember.js应用程序,在模型中,我将JSON作为对象加载。 (现在暂时显示。)

这是我的rails架构:

  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

ember中的序列化器:

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

制作模型的正确方法是什么?这是我得到的最好的,但我不确定如何正确导入json。如果更容易,字符串就可以了:

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')

非常感谢!

编辑:我想我想出来了 - 导入json作为一个字符串工作得很好,除了它从最终的网页中删除'{}'。而不是'int'我应该使用'数字'。

0 个答案:

没有答案