Travis Smith
Travis Smith

Reputation: 632

How can I use a Rails helper inside Jbuilder with the Gon gem?

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

Answers (1)

Travis Smith
Travis Smith

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

Related Questions