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

后端 未结 2 1124
清歌不尽
清歌不尽 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 -

    All
    

    whereas using the hash will generate something similar to

    All
    

提交回复
热议问题