Rails js.erb file cannot find method “render”

后端 未结 3 1442
遥遥无期
遥遥无期 2020-11-27 19:57

I\'ve got the following code in a Javascript ERB file:

$(document).ready(function() {
  $(\"#workout-week\").append(
    <%= escape_javascript(render :par         


        
3条回答
  •  忘掉有多难
    2020-11-27 20:02

    With the new asset pipeline, inside static assets (/app|lib|vendor/assets/) you can use some 'static' helpers (i.e. <%= asset_path "/foo/bar" %>), because you just compile them once (if you're on production i.e.) and not every time you make an http req. Therefore, it makes no sense to use methods like render (or general 'dynamic' stuff) inside a static asset.

    For your particular case, you could use both *.js.erb views (that will 'match' a particular action inside the controller) or javascript rendered directly inside the html.

提交回复
热议问题