我的 RABL 文件有什么问题?
What is wrong with my RABL file?
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}}
我们将不胜感激。
我认为您的方向是正确的。我会做一个小的改变。您不需要将 @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
如果问题不在于您的 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
对于 children 你会有像这样的单独文件:
app\views\tickets\projects.json.rabl 将包含
collection @projects
extends "projects/show"
但还要确认属性无论如何都与您的架构匹配。
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}}
我们将不胜感激。
我认为您的方向是正确的。我会做一个小的改变。您不需要将 @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
如果问题不在于您的 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
对于 children 你会有像这样的单独文件: app\views\tickets\projects.json.rabl 将包含
collection @projects
extends "projects/show"
但还要确认属性无论如何都与您的架构匹配。