Updating variable from different model rails -


my system has review process paper object. want update paper status published if 3 reviews paper accepted.

i've made review part , works. user reviews paper , once review accepted paper given point.

is there way can implement using ajax once review points has come 3, update paper status in database published?

what i've done doesn't update paper's status shows it's published:

<p class="status">     <strong>status:</strong>     <% status = 0 %>     <% @paper.reviews.each |review| %>         <% status += review.review_status %>     <% end %>     <% if status >= 3 %>         paper published     <% else %>         paper under reviewing process     <% end %> <p> 

paper model:

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' 

review model:

belongs_to :user belongs_to :paper 

you should use acts_as_state_machine maintain state of paper

checkout https://github.com/aasm/aasm

class paper < activerecord::base   include aasm    aasm     state :under_review, intial: true     state :published      event :publish       transitions from: :under_review, to: :published     end   end  end 

whenever reviews paper check if review point equal or greater 3 change paper state published.

paper.publish! 

donot forget add aasm_state column in paper table.

doing ajax no different, update paper state in view when review point greater or equal 3.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -