Navigating jbuilder to attatch html string

65 Views Asked by At

I am setting up a collection of ruby issues (@issues) into arrays using jbuilder so they plug into datatables. Normally with datatables each row represents a single record and you determine the columns by their fields (:id, :name, etc)

In this case each issue has a status (:initial, waiting_on_customer, waiting_on_user, waiting_on_supplier, closed) and is sorted in the controller so the @issues object looks like this where each "row" is comprised of 5 issues, one for each status

{
initial: {
id: 3,
priority: "Low",
status: "initial",
name: "Broken Parts",
notes: "shaft was bent",
created_at: "2020-11-20T00:45:40.000Z",
updated_at: "2020-11-23T15:39:59.000Z",
purchase_order_id: null,
deleted_at: null,
tenant_id: null,
supplier_id: null,
incoming_order_id: null
},
waiting_on_user: {
id: 8,
priority: "Medium",
status: "waiting_on_user",
name: "Poor Communication",
notes: "Supplier wont return call",
created_at: "2020-11-20T05:56:49.000Z",
updated_at: "2020-11-23T22:39:25.000Z",
purchase_order_id: null,
deleted_at: null,
tenant_id: null,
supplier_id: 2,
incoming_order_id: null
},
waiting_on_supplier: {
id: 4,
priority: "Low",
status: "waiting_on_supplier",
name: "Payment reversed",
notes: "Check bounced",
created_at: "2020-11-20T00:46:02.000Z",
updated_at: "2020-11-23T22:39:31.000Z",
purchase_order_id: null,
deleted_at: null,
tenant_id: null,
supplier_id: null,
incoming_order_id: null
},
waiting_on_customer: {
id: 1,
priority: "Medium",
status: "waiting_on_customer",
name: "Big Problem",
notes: "Mayday were going down!!",
created_at: "2020-11-20T00:44:34.000Z",
updated_at: "2020-11-23T15:42:52.000Z",
purchase_order_id: null,
deleted_at: null,
tenant_id: null,
supplier_id: null,
incoming_order_id: null
},
closed: {
id: 2,
priority: "High",
status: "closed",
name: "Lost Package",
notes: "Missing package, shipper says it was delivered",
created_at: "2020-11-20T00:45:16.000Z",
updated_at: "2020-11-23T15:39:01.000Z",
purchase_order_id: null,
deleted_at: null,
tenant_id: null,
supplier_id: null,
incoming_order_id: null
}
},

@issues gets passed to index.json.jbuilder

json.array! @issues, partial: "issues/issue", as: :issue_hash

which passes each issue_hash to the issue.json.jbuilder

json.extract! issue_hash, :initial, :waiting_on_user, :waiting_on_supplier, :waiting_on_customer, :closed

I can add the string to the base level of the issue_hash with

json.issue_card_html render 'issue_card_datatable.html.erb',i: issue

But I am trying to attach this html string to the "initial" issue object like so

# json.initial.issue_card_html render 'issue_card_datatable.html.erb',i: issue

but It gets me a no method error for issue_card_html Ive tried every combination of looping and diving into the json objects I can think of and that are on the jbuilder docs to no avail. I think I must be missing something obvious as it shouldn't be this hard to navigate and manipulate a json object

0

There are 0 best solutions below