Skip to content

Instantly share code, notes, and snippets.

Created September 11, 2014 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/9141aa0d7811b76bd15a to your computer and use it in GitHub Desktop.
Save anonymous/9141aa0d7811b76bd15a to your computer and use it in GitHub Desktop.
def print_example
@print = Pdf::TicketDetail.find(params[:id])
drop = TicketDrop.new(@ticket)
drop.generate_ticket ({
: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"
})
@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 ({
: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"
})
return send_data(pdf.render, :type => 'application/pdf', :disposition => 'attachment', :filename => "Ticket-#{@ticket.name}-exmaple.pdf")
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