我对 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({
类型:'POST',
url: '/deals/' + id + '/vote_up',
成功:函数(){
//做东西
}
});
在我的deals_controller.rb:
def vote_up
如果 user_signed_in?
current_user.vote_exclusively_for(@deal = Deal.find(params[:id]))
渲染 :partial => 'deals/partials/interaction', :locals => {:deal => @deal}
结尾
结尾
这会将我重定向到页面并呈现部分内容,而不是像 AJAX 请求那样刷新它。