Search code examples
javascriptruby-on-railslink-to

Why is link_to in Rails not invoking javascripts for the linked page?


I have a link_to on my page and when I click on it, it takes me to the correct page, but no javascript gets executed. When I refresh the page, it works fine. How do I fix this so that link_to actually makes a new request to the server?

Thanks


Solution

  • You need to make your link remote so it executes your ajax request.

    An example of it would be as follows:

    <%= link_to my_path, method: :post, :remote => true do %>
      <i class="icon-update"></i>
    <% end %>
    

    Please post more information about your code in case this doesn't solve your problem.