2012-09-28 166 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請求