Guest User

Untitled

a guest
May 25th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. ## Document Model
  2. class Document < ActiveRecord::Base
  3. has_many :samples
  4. belongs_to :user
  5. belongs_to :verifier, :class_name => "User", :foreign_key => "verifier_id"
  6.  
  7. # . . .
  8. end
  9.  
  10. ## User Model
  11. require 'digest/sha1'
  12. class User < ActiveRecord::Base
  13. has_many :samples
  14. has_many :documents
  15. has_many :verified_documents, :class_name => "Document", :foreign_key => "verifier_id"
  16. has_many :verified_samples, :class_name => "Sample", :foreign_key => "verifier_id"
  17.  
  18. # . . .
  19. end
  20.  
  21. ## Verification Controller
  22. class VerificationsController < ApplicationController
  23.  
  24. # . . .
  25.  
  26. def update
  27. logger.debug params.inspect
  28. params[:document].each {| key, value |
  29. if value["verified"] == "1"
  30. logger.debug("LOADING DOCUMENT")
  31. @document = Document.find_by_id(key)
  32. logger.debug "FOUND DOCUMENT: #{@document.inspect}"
  33. logger.debug("USER ID: " + current_user.id.to_s)
  34. logger.debug("VERIFIER ID: " + @document.verifier_id.to_s)
  35. logger.debug("SETTING DOCUMENT VERIFIER")
  36. @document.verifier = current_user # Always sets verifier to false!
  37. logger.debug "DOCUMENT VERIFIER SET: #{@document.inspect}"
  38. logger.debug("USER ID: " + current_user.id.to_s)
  39. logger.debug("VERIFIER ID: " + @document.verifier_id.to_s)
  40. logger.debug("SAVING DOCUMENT")
  41. @document.save!
  42. end}
  43. redirect_to verifications_path
  44. end
  45. end
Add Comment
Please, Sign In to add comment