Rails - how to insert / display a file inside a view

in index.html.erb, I would like to know how to insert index.js.erb, something like:

<script type="text/javascript"> $(function() { <%= render =>"home/index.js.erb" %> }); </script> 

Any ideas on how to simply insert the index.js.erb file?

thanks

+4
source share
2 answers
 <%= File.read "#{RAILS_ROOT}/app/views/home/index.js.erb" %> 
+5
source

Install your file as partial and add a preview or do what you do with it.

For a partial file with the name _index.js.erb located in the same folder where the file with this code is called, DOMID will be added to the example.

 jQuery('#exemple').prepend("<%= escape_javascript(render(:partial => 'index')) %>"); 

Maybe you can make an html file with it ...

 <% javascript_tag do %> <%= render :partial => 'index' %> 

or direct code

 <% end %> 
+1
source

Source: https://habr.com/ru/post/1334614/


All Articles