Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Document Model
- class Document < ActiveRecord::Base
- has_many :samples
- belongs_to :user
- belongs_to :verifier, :class_name => "User", :foreign_key => "verifier_id"
- # . . .
- end
- ## User Model
- require 'digest/sha1'
- class User < ActiveRecord::Base
- has_many :samples
- has_many :documents
- has_many :verified_documents, :class_name => "Document", :foreign_key => "verifier_id"
- has_many :verified_samples, :class_name => "Sample", :foreign_key => "verifier_id"
- # . . .
- end
- ## Verification Controller
- class VerificationsController < ApplicationController
- # . . .
- def update
- logger.debug params.inspect
- params[:document].each {| key, value |
- if value["verified"] == "1"
- logger.debug("LOADING DOCUMENT")
- @document = Document.find_by_id(key)
- logger.debug "FOUND DOCUMENT: #{@document.inspect}"
- logger.debug("USER ID: " + current_user.id.to_s)
- logger.debug("VERIFIER ID: " + @document.verifier_id.to_s)
- logger.debug("SETTING DOCUMENT VERIFIER")
- @document.verifier = current_user # Always sets verifier to false!
- logger.debug "DOCUMENT VERIFIER SET: #{@document.inspect}"
- logger.debug("USER ID: " + current_user.id.to_s)
- logger.debug("VERIFIER ID: " + @document.verifier_id.to_s)
- logger.debug("SAVING DOCUMENT")
- @document.save!
- end}
- redirect_to verifications_path
- end
- end
Add Comment
Please, Sign In to add comment