Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
Load Javascript File for Ajax (js.erb)

For my current design, I have 3 menus that load different content, so I decided to use Ajax render and js.erb files.

An example of this:

controller:

def my_route
  respond_to do |format|
    format.js
  end
end

my_route.js.erb:

$('#content').html("<%= j render 'my_route_partial' %>");

This loads my page, but in the main_page which loads the three Ajax content, I have:

<% content_for :javascripts do %>
  <%= include_javascript_tag 'my_javascript_file' %>
<% end %>

This loads the javascript related to the main page, but it does not load the javascript that should work with any of the pages loaded through Ajax afterwards.

I have also tried to just include the javascript tag into the files, but it didn't work. I don't want to leave the javascript code into the js.erb file, so is there any way to do it?

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!