Rails 3.1 link_to remote => true renders HTML instead of JS, the same code works in some cases

后端 未结 2 1123
清歌不尽
清歌不尽 2021-01-16 08:29

This is the code I have in rails 3.1

<%= link_to \'All\',:action => \"bycategory\", :id => \'All\', :remote => true %>

I hav

相关标签:
2条回答
  • 2021-01-16 08:50

    You might want to put the :action => "bycategory" and :id => 'All' in a hash as

    <%= link_to 'All', { :action => "bycategory", :id => 'All' }, :remote => true %>
    

    This will generate the proper html attribute i.e. data-remote="true" otherwise it will simply treat everything following as an http request attribute. Your code will generate -

    <a href="/bycategory?id=All&amp;remote=true">All</a>
    

    whereas using the hash will generate something similar to

    <a data-remote="true" href="/bycategory/All">All</a>
    
    0 讨论(0)
  • 2021-01-16 09:03

    I had the same problem with Rails 3.1.3 and I cured it with rake assets:precompile,but ensure you have in application.js "//= require jquery_ujs" instead of "//= require jquery",this was the main problem and I spent at least 12 hours before I decided do it this way!Terrible!

    0 讨论(0)
提交回复
热议问题