开发者

Why is this code throwing an ActionView::TemplateError

开发者 https://www.devze.com 2023-01-22 09:30 出处:网络
I have some straight forward code that looks like the following in one of my erb templates: if (<%= is_defined? foo %>) /* some j开发者_如何学Pythonavascript to do stuff with foo */

I have some straight forward code that looks like the following in one of my erb templates:

if (<%= is_defined? foo %>) /* some j开发者_如何学Pythonavascript to do stuff with foo */

Is there a reason that code is throwing an ActionView::TemplateError exception saying `undefined local variable or methodfoo'? I thought is_defined?() should take care of that and not try to execute the code after utilizing foo if it isn't defined?


it's because you not define the foo method or variable in your view. Define it. You not generate some javascript. You generate some ruby code.

0

精彩评论

暂无评论...
验证码 换一张
取 消