0

Hi i tried to find the example, but it's hard to find any, so can you give example code how to render other file (in my case is .js.erb file) inside JS? let say i want to render it inside like this:

$("#btn").click(function(e) {
  // render partial .js.erb file in here
}

Thanks

  • the better way to render js file is https://stackoverflow.com/a/9170967/10739704 – Dev.rb Mar 24 '21 at 06:57
  • @nileshkumar i don't want inside the controller, it must on JS, is that imposible? – Muhammad Jafar Mar 24 '21 at 07:10
  • Just use `<%= render(partial: "partial_name") %>` and make sure that the js partial is following Rails naming conventions. – spickermann Mar 24 '21 at 07:37
  • How can i write the format tag like that inside jquery? it's still not inside .js.erb file but it's on html take a look at my example code above, it's on button click action @spickermann – Muhammad Jafar Mar 31 '21 at 04:12
  • You can only include partials in ERB files. That means into HTML that is generated with ERB or into JS that is generated with ERB. When you have JS code that is not processed with ERB, for example, code from an internal source, then you obviously cannot include partials. That means if you want to use partials then the files that should include the partials need to be generated with ERB too. – spickermann Mar 31 '21 at 06:53

0 Answers0