[英]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,從導軌的角度來看,這是對我有用的結構。 檢查您的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"
而且還要確認屬性是否與您的架構匹配。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.