Sha256: 2d10a13cc0560643648697b0323d58e0556ffeed51cc1438c7516728f5c2e1dc

Contents?: true

Size: 1.59 KB

Versions: 3

Compression:

Stored size: 1.59 KB

Contents

module Pwb
  class Export::PropertiesController < ApplicationApiController
    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 = [: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

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pwb-1.0.0 app/controllers/pwb/export/properties_controller.rb
pwb-0.1.1 app/controllers/pwb/export/properties_controller.rb
pwb-0.1.0 app/controllers/pwb/export/properties_controller.rb