Class: Export::PropertiesController

Inherits:
ApplicationApiController
  • Object
show all
Defined in:
app/controllers/pwb/export/properties_controller.rb

Instance Method Summary collapse

Instance Method Details

#allObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/pwb/export/properties_controller.rb', line 3

def all
  properties = Pwb::Prop.all
  # where(:id,)
  # @header_cols = ["Id", "Title in English", "Title in Spanish",
  #                 "Description in English", "Description in Spanish",
  #                 "Sale price", "Rental Price",
  #                 "Number of bedrooms", "Number of bathrooms", "Number of toilets", "Number of garages",
  #                 "Street Address", "Street Number", "Postal Code",
  #                 "City", "Country", "Longitude", "Latitude"]
  @prop_fields = i[id title_en title_es
                    description_en description_es
                    price_sale_current_cents price_rental_monthly_current_cents
                    count_bedrooms count_bathrooms count_toilets count_garages
                    street_address street_number postal_code
                    city country longitude latitude]
  @props_array = []
  properties.each do |prop|
    prop_field_values = []
    @prop_fields.each do |field|
      # for each of the prop_fields
      # get its value for the current prop
      prop_field_values << (prop.send field)
      # prop[field] would work instead of "prop.send field" in most
      # cases but not for title_es and associated fields
    end
    @props_array << prop_field_values
  end
  headers['Content-Disposition'] = "attachment; filename=\"pwb-properties.csv\""
  headers['Content-Type'] ||= 'text/csv'
  render "all.csv"
end