Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda