how to render partial and a variable on same page using jbuilder gem

328 Views Asked by At

I am using Rails 4, ruby 2, and jbuilder gem to respond json.

I have a file index.json.jbuilder in which following code is written

json.partial! "apis/contents", comments: @comments
json.name @name

Returning following error :-

no implicit conversion of String into Integer
1

There are 1 best solutions below

2
On

I think it might be due to the collection of objects, you can define partial explicitly, like this:

json.partial! partial: 'apis/contents', collection: @comments, as: :comment