-
-
Save tubbo/6b44a6dda0962f7d4552 to your computer and use it in GitHub Desktop.
This file contains 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
def print_example | |
@print = Pdf::TicketDetail.find(params[:id]) | |
drop = TicketDrop.new(@ticket) | |
drop.generate_ticket TicketAttrs.for(session) | |
@output = Liquid::Template.parse(@print.body).render('pdf_ticket_details' => drop).html_safe | |
render layout: false | |
end | |
def create_example | |
@ticket = Pdf::Ticket.find(params[:id]) | |
pdf = @ticket.generate_ticket TicketAttrs.for(session) | |
return send_data(pdf.render, :type => 'application/pdf', :disposition => 'attachment', :filename => "Ticket-#{@ticket.name}-exmaple.pdf") | |
end | |
class TicketAttrs | |
include ActiveModel::Model | |
attr_accessor :session | |
def self.for(session) | |
new(session: session).attributes | |
end | |
def attributes | |
{ | |
:settings=>session[:settings], | |
:slot=>Slot.new(:date=>Date.today), | |
:space=>::Space.new(:qty=>1), | |
:address=>Address.new(:address1=>"Ex Address1", :address2=>"Ex Address2", :address3=>"Ex Address3", :address4=>"Ex Address4", :postcode=>"Ex Postcode", :country=>"Ex Country"), | |
:ref=> "12345678", | |
:session=> Session.new(:name=>"My event", :description=>"This is a description of the event"), | |
:title=> "My Event Title", | |
:member=> Member.new(:first_name=>"John", :last_name=>"Smith", :email=>"john@smith.com"), | |
:voucher=>Price::Voucher.new(:code=>"1234567890", :value=>100, :purchase_date=>Date.today), | |
:voucher_type=>Price::VoucherType.new(:voucher_style=>Price::VoucherType::BB_MONEY, :value=>100, :name=>"An example"), | |
:company=>session[:goldberg][:company], :recipient_name=>"Fred Bloggs", :recipient_email=>"fred@bloggs.com" | |
} | |
end | |
end | |
=begin | |
I can not put the hash in a constant because it contains the session and as stated by elaptics the session is not something that is static. SO my question is how would I reduce the above so it is not duplicated? FYI these two instance methods sit in a model | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment