我对Rails还是比较新的所以请耐心等待。如何刷新部分并停留在页面而不是仅渲染部分?
在_interaction.html.haml
:
%div.vote_up.pull-left = link_to('', vote_up_deal_path(deal), :method => :post, :class => 'icon-thumbs-up interaction_button', :id => "vote_up_#{deal.id}")
在'votes.js'中:
$.ajax({ type: 'POST', url: '/deals/' + id + '/vote_up', success: function() { //do stuff } });
在我的deals_controller.rb
:
def vote_up if user_signed_in? current_user.vote_exclusively_for(@deal = Deal.find(params[:id])) render :partial => 'deals/partials/interaction', :locals => {:deal => @deal} end end
这会将我重定向到页面并呈现部分而不是像AJAX请求那样刷新它。
答案 0 :(得分:0)
尝试
= link_to('', vote_up_deal_path(deal), :method => :post, :remote=>true,
:class => 'icon-thumbs-up interaction_button', :id => "vote_up_#{deal.id}")
因为:remote说它是ajax请求