Home>

I don't know how to use Rails remote: true

views/test.html.erb

link_to "test", test_path, remote: true

That place

<a href ="/test"data-remote ="true">test</a>

The link

was generated

views/test.js

alert ("test");
even if a link was inserted at the same place, a page transition occurred and test.html.erb was displayed

I thought this JS was executed in ajax and popped up without page transitions. Is it recognized differently?
I felt like moving JS in view once with remote: true ...

Isn't my Rails running anymore, so are there any special settings that disable ajax ...

The Rails version is 4.2.3

Thank you for any hints

  • Answer # 1

    In application.js

    require jquery_ujs


    now works after adding

    Reference:
    http://d.hatena.ne.jp/mercystage/20130207/1360173048

  • Answer # 2

    The controller side may not support Ajax.

    respond_to do | format |
      format.html {redirect_to user}
      format.js
    end


    If the code like is not written in the controller, I think you need to add.