Holizontally alighning two sets of data using Prawn in Rails

17 Views Asked by At

So I am desigiing an invoice with Prawn gem I have the below two sets of data that I want on the same line. left_address to the left and right_address to the right. As it is, the right-address is appearing below left-address.

def left_address(property)
 move_down 5
 line1 = property.detect { |n| n.property == 'Address1' }
 line2 = property.detect { |n| n.property == 'Address2' }
 line3 = property.detect { |n| n.property == 'Address3' }
 text line1.value
 text line2.value
 text line3.value
end

def right_address(property)
 move_down 5
 phone = property.detect { |n| n.property == 'Phone' }
 cell = property.detect { |n| n.property == 'Cell' }
 email2 = property.detect { |n| n.property == 'Email2' }
 text phone.value, :align => :right
 text cell.value, :align => :right
 text email2.value, :align => :right
end

I have tried

 def left_address(property)
  line1 = property.detect { |n| n.property == 'Address1' }
  line2 = property.detect { |n| n.property == 'Address2' }
  line3 = property.detect { |n| n.property == 'Address3' }

  bounding_box([0, cursor], width: bounds.width / 2) do
  text line1.value
  text line2.value
  text line3.value
 end
end

 def right_address(property)
  phone = property.detect { |n| n.property == 'Phone' }
  cell = property.detect { |n| n.property == 'Cell' }
  email2 = property.detect { |n| n.property == 'Email2' }

  bounding_box([bounds.width / 2, cursor], width: bounds.width / 2, :align => :right) do
  text phone.value, :align => :right
  text cell.value, :align => :right
  text email2.value, :align => :right
 end
end

I have also tried

def combined_addresses(property)
 move_down 5

 column_box([0, cursor], columns: 2, width: bounds.width, height: bounds.height) do
 line1 = property.detect { |n| n.property == 'Address1' }
 line2 = property.detect { |n| n.property == 'Address2' }
 line3 = property.detect { |n| n.property == 'Address3' }

 text line1.value
 text line2.value
 text line3.value

 next_column

 phone = property.detect { |n| n.property == 'Phone' }
 cell = property.detect { |n| n.property == 'Cell' }
 email2 = property.detect { |n| n.property == 'Email2' }

 text phone.value, align: :right
 text cell.value, align: :right
 text email2.value, align: :right
end
end

Nothing works. The right address goes to the right but still below the left_address. I want them horizontally aligned.

Below is my initialization

class GuestAccountPdf < Prawn::Document
 include ApplicationHelper

 def initialize(guest_id)
 super(top_margin: 70)
 guest = Guest.find(guest_id)
 lodging = CheckIn.where(guest_id: guest_id).last
 xtrasrvc = ViewExtraService.where(guest_id: guest_id)
 property = Property.all


 business_name(property)
 report_title
 left_address(property)
 right_address(property)

 combined_addresses(property)

 guest_demos(guest)
 lodging_details(lodging)
 create_table(xtrasrvc)
 grand_total(lodging, xtrasrvc)
end

end

left_address(property), right_address(property), combined_addresses(property) are used interchangeably when tasting.

0

There are 0 best solutions below