gazay / gon

Your Rails variables in your JS
MIT License
3.05k stars 184 forks source link

json.cache! is not working when using gon.jbuilder #247

Open nullnull opened 6 years ago

nullnull commented 6 years ago

Hi. I found that json.cache! was not working when I was using jbuilder template with gon.jbuilder. I found this error message: undefined method controller' for #<StaffsController:0x007f984fb67440> Did you mean? controller_path The error comes from this line. https://github.com/rails/jbuilder/blob/master/lib/jbuilder/jbuilder_template.rb#L35

I think this problem will be fixed by changing the argument controller to right one. (controller is equal to @context on JbuilderTemplate) https://github.com/gazay/gon/blob/master/lib/gon/jbuilder/parser.rb#L69

Is it hard to replace it? And is there other way to use json.cache! when using gon.jbuilder?

Thanks.

gazay commented 6 years ago

Hello! I'm not sure as I didn't touch jbuilder parsing code for a long time and didn't plan to do so in near future. But if you find out that it is possible and will be compatible with old behavior - we can try to fix it

Thank you for issue!