How to include js.erb file in view folder

前端 未结 2 1544
挽巷
挽巷 2021-01-05 06:55

I have a JavaScript file to use with a view. There needs to be Ruby code in it, and I need to do render in Ruby, so I understand that I can\'t put the JavaScrip

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-05 07:45

    you can do this by

    render :partial => "myfile"
    

    you have to keep your file in controller's view directory with name _myfile.js.erb

    Now you can write your own code (js,ruby) here and probably can separate out js with javascript_include_tag to avail asset pipline

    This file will be first rendered by erb engine and then as javascript.

提交回复
热议问题