我的系统对其Paper对象有一个审阅过程。我想做的是,如果论文的3篇评论被接受,则将论文状态更新为已发布。
我已经完成了复习部分,并且它起作用了。用户基本上对论文进行了评论,一旦评论被接受,论文就会被给予一个分数。
有没有一种方法可以让我使用AJAX实现,这样一旦审阅点数达到3,它就会将数据库中的论文状态更新为已发布?
我所做的没有更新论文的状态,但显示它已发布:
<p class="status">
<strong>Status:</strong>
<% status = 0 %>
<% @paper.reviews.each do |review| %>
<% status += review.review_status %>
<% end %>
<% if status >= 3 %>
Paper published
<% else %>
Paper under reviewing process
<% end %>
<p>纸张模型:
belongs_to :user
belongs_to :subject
has_many :comments
has_many :reviews
#file dependencies
has_attached_file :pdf,
:url => "/assets/:attachment/:id/:basename.:extension",
:path => ":rails_root/public/assets/pdfs/:id/:basename.:extension"
#validations
validates :title, presence: true, length: { maximum: 150 }
validates :subject_id, presence: true
validates :version, presence: true
validates_attachment_content_type :pdf, :content_type => 'application/pdf'查看模型:
belongs_to :user
belongs_to :paper发布于 2014-04-24 13:09:25
您应该使用acts_as_state_machine来维护纸张的状态
检出https://github.com/aasm/aasm
class Paper < ActiveRecord::Base
include AASM
aasm do
state :under_review, intial: true
state :published
event :publish do
transitions from: :under_review, to: :published
end
end
end每当有人审阅论文时,检查评审点是否等于或大于3,然后将论文状态更改为已发布。
paper.publish!不要忘记在纸质表格中添加aasm_state列。
使用Ajax也不例外,只需在审阅点大于或等于3时在视图中更新论文状态。
https://stackoverflow.com/questions/23259533
复制相似问题