Guest User

Untitled

a guest
Jul 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #Using active model
  2. class Upload
  3. require 'grit'
  4. include Grit
  5. include ActiveModel::Validations
  6. include ActiveModel::Conversion
  7. extend ActiveModel::Naming
  8.  
  9. attr_accessor :message, :upload
  10. #attr_accessible :message, :upload, :repo
  11. #validates the presence of something in the message field
  12. validates :message, :presence => true, :length => { :maximum =>50}
  13. validates :upload, :presence => true
  14.  
  15. #Creates hash for storing the info about the uploaded file for validation
  16. def initialize(attributes = {})
  17. attributes.each do |name, value|
  18. send("#{name}=", value)
  19. end
  20. end
  21.  
  22. #takes the upload object and extracts the file.
  23. def filesave
  24. # Calls the .original_filename method on the upload object and stores in the
  25. # variable name
  26. name = upload.original_filename
  27. directory = "/home/resource_portal/website/public/data/upload"
  28. # create the file path
  29. path = File.join(directory, name)
  30. # write the file
  31. File.open(path, "wb") { |f| f.write(upload.read) }
  32. # commit the file to the git repo
  33. committer = @user
  34. repo = Grit::Repo.new("/home/resource_portal/website/public/data/upload")
  35. index = Index.new(repo)
  36. index.add(name, message)
  37. #index.commit(message)
  38. repo.commit_all(message)
  39. end
  40. end
  41.  
  42. committer = @user
  43. repo.commit_all(message, user)
Add Comment
Please, Sign In to add comment