Rails 3.2 jQuery的摆幅
我已经搜遍了所有搜索结果,而且我只找到了js方法来更新部分内容或通过JS添加部分内容。我对这个没有运气。这是问题所在:
我在页面上有一个推荐列表,推荐在索引页面上作为部分发布。推荐框有一个回复按钮和每个推荐回复的数量。静静地我让它工作但我没有用新计数更新推荐框并用图标替换回复按钮。正在进入数据库,但是我正在通过刷新盒子搞砸了。求救!
class RepliesController < ApplicationController
respond_to :html, :js
def new
@referral = Referral.find(params[:referral_id])
@reply = @referral.replies.new(:user_id => params[:user_id], :referral_id => params[:referral_id])
if @reply.save
format.html { notice: 'Replied' }
respond_with(@referral, :location => referrals_path)
end
end
end
.referralBox.cornerShadow{:id => "Referral#{referral.id}"}
- if current_user == referral.user or current_user.role == 'administrator'
= link_to '<i class="icon-pencil icon-large icon-grey" rel="tooltip" title="Edit"></i>'.html_safe, edit_referral_path(referral), class: "referralEdit"
= link_to '<i class="icon-remove icon-large icon-grey" rel="tooltip" title="Delete"></i>'.html_safe, referral, method: :delete, data: { confirm: 'Are you sure?' }, class: "referralClose"
.referralProfile
= link_to "#{image_tag(referral.user.image.url, :class => "img-circle img-border border-white", :style => "thumb")}".html_safe, referral.user
%ul.unstyled.inline
%li
= referral.description
- unless referral.replies.count == 0
- if referral.user == current_user
%i.icon-comments.icon-large{"rel" => "tooltip", "title" => "Replies"}
= referral.replies.count
- else
%i.icon-comments.icon-large.orange{"rel" => "tooltip", "title" => "Replies"}
= referral.replies.count
- unless current_user == referral.user
- if referral.replies.any?
%i.icon-ok.icon-large.pull-right.orange{"rel" => "tooltip", "title" => "Replied"}
- else
= link_to '<i class="icon-ok icon-large pull-right icon-grey" rel="tooltip" title="Reply"> Reply</i>'.html_safe, new_referral_reply_path(:referral_id => referral.id, :user_id => current_user.id), :id => "ReplySubmit", :remote => true
$(".referralBox").html("<%= j(render(:partial => "@referral")) %>");
jQuery.ajaxSetup({
'beforeSend': function (xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
});