Class: Glengarry::EmailLeadsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/glengarry/email_leads_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate

Instance Method Details

#createObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/glengarry/email_leads_controller.rb', line 28

def create
  @email_lead = EmailLead.new(params[:email_lead])
  @email_lead.ip_address = request.ip
  @email_lead.referer = request.referer

  respond_to do |format|
    if @email_lead.save
      format.html { redirect_to :back, notice: ['Thank you.'] }
      format.json { render json: @email_lead, status: :created, location: @email_lead }
    else
      format.html { redirect_to :back, notice: @email_lead.errors }
      format.json { render json: @email_lead.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject



44
45
46
47
48
49
50
51
52
# File 'app/controllers/glengarry/email_leads_controller.rb', line 44

def destroy
  @email_lead = EmailLead.find(params[:id])
  @email_lead.destroy

  respond_to do |format|
    format.html { redirect_to email_leads_url }
    format.json { head :no_content }
  end
end

#downloadObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/glengarry/email_leads_controller.rb', line 54

def download
  respond_to do |format|
    format.csv {
        @emails = EmailLead.all
        @columns = ["Email", "IP Address", "Referer", "Latitude", "Longitude", "City", "Country"].to_csv
        @filename = "emails-#{Date.today.to_s(:db)}"

        self.response.headers["Content-Type"] ||= 'text/csv'
        self.response.headers["Content-Disposition"] = "attachment; filename=#{@filename}"
        self.response.headers["Content-Transfer-Encoding"] = "binary"

        self.response_body = Enumerator.new do |y|
          @emails.each_with_index do |email, i|
            if i == 0
              y << @columns
            end
            y << [email.email, email.ip_address, email.referer, email.lat, email.long, email.city, email.country].to_csv
          end
        end
      }
  end
end

#indexObject



9
10
11
12
13
14
15
16
17
# File 'app/controllers/glengarry/email_leads_controller.rb', line 9

def index
  @email_leads = EmailLead.page(params[:page]).per(10)
  @email_lead_count = EmailLead.count

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @email_leads }
  end
end

#showObject



19
20
21
22
23
24
25
26
# File 'app/controllers/glengarry/email_leads_controller.rb', line 19

def show
  @email_lead = EmailLead.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @email_lead }
  end
end