AnApprentice
AnApprentice

Reputation: 110950

Rails - how to insert/render 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 just insert the index.js.erb file ?

thanks

Upvotes: 4

Views: 2020

Answers (2)

4nkh
4nkh

Reputation: 11

Set your file as a partial and append preprend or do what you wana do with it.

For a partial file named _index.js.erb located in the same folder of where the file with this code is called will be prepend in the DOMID exemple.

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

Maybe you can do a html file with it...

<% javascript_tag do %>

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

or direct code

<% end %>

Upvotes: 1

cam
cam

Reputation: 14222

<%= File.read "#{RAILS_ROOT}/app/views/home/index.js.erb" %>

Upvotes: 5

Related Questions