我想像下面一样使用link_to,但它不起作用。它没有做任何事情:(
<% unless user == current_user %>
<% if current_user.following?(user) %>
<%= link_to sanitize('<i class="icon-remove icon-white"></i> ') + 'Un-Follow', user_follow_path(user.to_param, current_user.get_follow(user).id), :method => :delete, :remote => true, :class => 'btn' %>
<% else %>
<%= link_to sanitize('<i class="icon-ok icon-white"></i> ') + 'Follow', user_follows_path(user.to_param), :remote => true, :class => 'btn btn-primary' %>
<% end %>
<% end %>
但是,如果我像下面这样使用 button_to 对其进行编码,则它可以完美运行。为什么???
<% unless user == current_user %>
<% if current_user.following?(user) %>
<%= button_to("Un-Follow #{user.username}", user_follow_path(user.to_param, current_user.get_follow(user).id), :method => :delete, :remote => true) %>
<% else %>
<%= button_to("Follow #{user.username}", user_follows_path(user.to_param), :remote => true) %>
<% end %>
<% end %>