2012-09-28 129 views
0

我还是比较新的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

尝试

= link_to('', vote_up_deal_path(deal), :method => :post, :remote=>true, 
    :class => 'icon-thumbs-up interaction_button', :id => "vote_up_#{deal.id}") 

因为:远程说,这是Ajax请求