Rabl没有生成主要对象,但它正在为其子节点生成它。
我有一个Rails-Angularjs项目。我想使用RABL生成json文件。我已经阅读了RABL的文档并为动作节目创建了Rabl文件,该文件无法正常工作,如下所述:
object @ticket => :ticket do
attributes :id, :name, :subname, :description, :width, :height, :qty, :single, :double, :project_id, :material_id, :equipment_id, :location_id, :created_at, :updated_at
end
child :project do
attributes :name, :nickname, :project_number
end
child :job_state do
attributes :color, :name
end
child :location do
attributes :name
end
child :local_equipment do
attributes :name
end
child :local_material do
attributes :name
end
IF I
删除对象@ticket上的'do'和'end',它抛出错误:'wrong number of arguments (1 for 0)'.
如果我离开它们,它不会显示任何票证的字段名称。如下所示:
{"ticket":{"project":{"name":"Information Security Conference 2017","nickname":"infosecon17","project_number":1000},"job_state":{"color":"red","name":"printed"},"location":{"name":"Grand prairie graphics"},"local_equipment":null,"local_material":null}}
任何帮助将不胜感激。
如果问题不在你的Angular上,从rails侧面来看,这是适合我的结构。检查您的Tickets #show文件是否在此处并命名为:app \ views \ tickets \ show.json.rabl并仅包含
object @ticket
attributes :id, :name, :subname, :description, :width, :height, :qty, :single, :double, :project_id, :material_id, :equipment_id, :location_id, :created_at, :updated_at
对于孩子们,你会有这样的单独文件:app \ views \ tickets \ projects.json.rabl将包含
collection @projects
extends "projects/show"
但也要确认属性是否与您的架构匹配。
我认为你走在正确的轨道上。我会做一个小改动。您不需要在块中包装@ticket
属性。你可以指定object @ticket
并从那里开始。
object @ticket
attributes :id, :name, :subname, :description, :width, :height, :qty, :single, :double, :project_id, :material_id, :equipment_id, :location_id, :created_at, :updated_at
child :project do
attributes :name, :nickname, :project_number
end
child :job_state do
attributes :color, :name
end
child :location do
attributes :name
end
child :local_equipment do
attributes :name
end
child :local_material do
attributes :name
end