Created
July 2, 2014 15:54
-
-
Save msadoon/d7254dbf69a425903057 to your computer and use it in GitHub Desktop.
helper method use
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 ApplicationController < ActionController::Base | |
# Prevent CSRF attacks by raising an exception. | |
# For APIs, you may want to use :null_session instead. | |
protect_from_forgery with: :exception | |
helper_method :current_user | |
before_action :require_login | |
private | |
def require_login | |
unless current_user | |
flash[:error] = "You must be logged in to access this section" | |
redirect_to root_path # halts request cycle | |
end | |
end | |
def current_user | |
@current_user ||= User.find(session[:user_id]) if session[:user_id] | |
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 FillablePdfForm | |
require 'dropbox_sdk' | |
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 ||= user.mlease.url # this is where the error occurs, so I need a helper method to pull the current_user and then get the mlease url. Please help ! :) | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you initialize your
FillablePdfForm
viaFillablePdfForm.new()
, supply as an argument the current user, e.g.: