从控制器渲染部分

时间:2012-09-28 01:08:54

标签: ruby-on-rails ajax

我对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请求那样刷新它。

1 个答案:

答案 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请求