Created
July 2, 2014 00:16
-
-
Save msadoon/573dfac0e95384bff376 to your computer and use it in GitHub Desktop.
Retrieve template_path for PDFTK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FillablePdfForm | |
attr_writer :template_path | |
attr_reader :attributes | |
def initialize | |
fill_out | |
end | |
def export(output_file_path=nil, tenantname) | |
output_path = output_file_path || "tmp/#{tenantname}_lease_#{Time.now}.pdf" # make sure tmp/pdfs exists | |
pdftk.fill_form template_path, output_path, attributes | |
output_path | |
end | |
def get_field_names | |
pdftk.get_field_names template_path | |
end | |
def template_path | |
@template_path ||= "https://www.dropbox.com/sh/7g43jx9tukv47xi/AADL-yVWw3cWVHOrTvrxe_4ga/master_lease.pdf" # makes assumption about template file path unless otherwise specified | |
end | |
protected | |
def attributes | |
@attributes ||= {} | |
end | |
def fill(key, value) | |
attributes[key.to_s] = value | |
end | |
def pdftk | |
@pdftk ||= PdfForms.new(ENV['PDFTK_PATH'] || '') # On my Mac, the location of pdftk was different than on my linux server. | |
end | |
def fill_out | |
raise 'Must be overridden by child class' | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
attr_accessor :password | |
before_save :encrypt_password | |
has_attached_file :avatar, :storage => :dropbox, | |
:dropbox_credentials => Rails.root.join("config/dropbox.yml"), | |
:styles => { :medium => "300x300>", :thumb=> "100x100>" }, | |
:default_url => "No_image_available.png", | |
:dropbox_options => { | |
:path => proc { "#{avatar_file_name}" } | |
} | |
has_attached_file :mlease, :storage => :dropbox, | |
:dropbox_credentials => Rails.root.join("config/dropbox.yml"), | |
:dropbox_options => { | |
:path => proc { "#{avatar_file_name}" } | |
} | |
has_attached_file :expadd, :storage => :dropbox, | |
:dropbox_credentials => Rails.root.join("config/dropbox.yml"), | |
:dropbox_options => { | |
:path => proc { "#{avatar_file_name}" } | |
} | |
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\z/ | |
validates_attachment :mlease, content_type: { content_type: "application/pdf", message: "Please only upload a pdf in this field" } | |
validates_attachment :expadd, content_type: { content_type: "application/pdf", message: "Please only upload a pdf in this field" } | |
validates_confirmation_of :password | |
validates_presence_of :password, :on => :create | |
validates_presence_of :email | |
validates_uniqueness_of :email | |
def self.authenticate(email, password) | |
user = find_by_email(email) | |
if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt) | |
user | |
else | |
nil | |
end | |
end | |
def encrypt_password | |
if password.present? | |
self.password_salt = BCrypt::Engine.generate_salt | |
self.password_hash = BCrypt::Engine.hash_secret(password, password_salt) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment