In Jbuilder, How Can you Generate an Array of IDs Without the 'ID' Key?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


In Jbuilder, How Can you Generate an Array of IDs Without the 'ID' Key?



I have the following Jbuilder setup but I'd like to output the 'uw_question_ids' as values only. No 'id:' key. Is this possible?


json.menu do
json.uw_question_ids menu.uw_questions do |uw_question|
json.(uw_question, :id)
end
end



Currently, the output JSON is...


"menu":{"uw_question_ids":[{"id":"17"}]}



I'd like it be...


"menu":{"uw_question_ids":[{"17"}]}




1 Answer
1



I figured it out... simple!


json.menu do
json.uw_question_ids product.uw_question_ids
end



I didn't realize that Rails gives you access to a 'collection_singular_ids' method (in my case, 'uw_question_ids') when you create has_many or has_and_belongs_to_many associations. That's what I needed.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

'Series' object is not callable Error / Statsmodels illegal variable name