Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Using active model
- class Upload
- require 'grit'
- include Grit
- include ActiveModel::Validations
- include ActiveModel::Conversion
- extend ActiveModel::Naming
- attr_accessor :message, :upload
- #attr_accessible :message, :upload, :repo
- #validates the presence of something in the message field
- validates :message, :presence => true, :length => { :maximum =>50}
- validates :upload, :presence => true
- #Creates hash for storing the info about the uploaded file for validation
- def initialize(attributes = {})
- attributes.each do |name, value|
- send("#{name}=", value)
- end
- end
- #takes the upload object and extracts the file.
- def filesave
- # Calls the .original_filename method on the upload object and stores in the
- # variable name
- name = upload.original_filename
- directory = "/home/resource_portal/website/public/data/upload"
- # create the file path
- path = File.join(directory, name)
- # write the file
- File.open(path, "wb") { |f| f.write(upload.read) }
- # commit the file to the git repo
- committer = @user
- repo = Grit::Repo.new("/home/resource_portal/website/public/data/upload")
- index = Index.new(repo)
- index.add(name, message)
- #index.commit(message)
- repo.commit_all(message)
- end
- end
- committer = @user
- repo.commit_all(message, user)
Add Comment
Please, Sign In to add comment