Reputation: 632
I'm using Jbuilder and Gon to structure my JSON responses into variables and pass them to my JS front-end. In the Jbuilder files, I'd like to access the helper methods I'm using from the Money-Rails gem. However, if I try something like this...
// edit.json.jbuilder
json.minimum_premium money_without_cents limit.minimum_premium
I get an undefined method `money_without_cents' for #<Gon::Jbuilder::Parser:0x00007fbb6ebca198>
error.
Is there a trick to using helper methods inside Jbuilder when using the Gon gem?
Upvotes: 3
Views: 1750
Reputation: 632
This worked, though there might be better solutions...
// edit.json.jbuilder
json.minimum_premium ActionController::Base.helpers.money_without_cents limit.minimum_premium
Upvotes: 1