我在 Rails 应用程序中使用 RABL 通过 REST 访问数据。除了 if 语句外,它正在工作。
我收到此错误:
undefined local variable or method `matitem_id'
这是我的 show.json.rabl 代码:
object @expense
attributes :id, :unitcost, :quantity, :markup, :exp_date, :created_at, :description, :pcard, :invoice
child :employee do
attributes :id, :maxname
end
child :vendor do
attributes :id, :vendor_name
end
if matitem_id != nil
child :matitem do |matitem|
attributes :id, :itemnum
end
end
更新1
我也试过
if @expense.matitem_id != nil