Class: AdMan::AdvertisementsController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper
Defined in:
app/controllers/ad_man/advertisements_controller.rb

Instance Method Summary collapse

Methods included from ApplicationHelper

#js_link_to_ad, #link_to_ad

Instance Method Details

#click_throughObject

Click Through



95
96
97
98
99
100
# File 'app/controllers/ad_man/advertisements_controller.rb', line 95

def click_through
  @advertisement = AdMan::Advertisement.find(params[:id])
  @advertisement.click_count += 1 
  @advertisement.save
  redirect_to @advertisement.destination_url
end

#createObject

POST /advertisements POST /advertisements.json



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/ad_man/advertisements_controller.rb', line 49

def create
  @advertisement = AdMan::Advertisement.new(params[:advertisement])
  #@advertisement.keyword_id = params[:keyword_id]
  #@advertisement.priority = params[:priority]
  respond_to do |format|
    if @advertisement.save
      format.html { redirect_to @advertisement, notice: 'Advertisement was successfully created.' }
      format.json { render json: @advertisement, status: :created, location: @advertisement }
    else
      format.html { render action: "new" }
      format.json { render json: @advertisement.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /advertisements/1 DELETE /advertisements/1.json



84
85
86
87
88
89
90
91
92
# File 'app/controllers/ad_man/advertisements_controller.rb', line 84

def destroy
  @advertisement = AdMan::Advertisement.find(params[:id])
  @advertisement.destroy

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

#editObject

GET /advertisements/1/edit



43
44
45
# File 'app/controllers/ad_man/advertisements_controller.rb', line 43

def edit
  @advertisement = AdMan::Advertisement.find(params[:id])
end

#get_adObject



102
103
104
105
106
107
# File 'app/controllers/ad_man/advertisements_controller.rb', line 102

def get_ad()
  keyword = params[:key]
  @div = params[:div]
  @size = params[:size]
  @ad = js_link_to_ad(keyword)
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/ad_man/advertisements_controller.rb', line 6

def index
  @advertisements = AdMan::Advertisement.all

  # depends on the "will_paginate" gem
  #@advertisements = AdMan::Advertisement.paginate :page => params[:page], :order => 'created_at desc', 
  #	:per_page => 5
  @keywords = AdMan::Keyword.all
  
  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @advertisements }
  end
end

#newObject

GET /advertisements/new GET /advertisements/new.json



33
34
35
36
37
38
39
40
# File 'app/controllers/ad_man/advertisements_controller.rb', line 33

def new
  @advertisement = AdMan::Advertisement.new

  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @advertisement }
  end
end

#showObject

GET /advertisements/1 GET /advertisements/1.json



22
23
24
25
26
27
28
29
# File 'app/controllers/ad_man/advertisements_controller.rb', line 22

def show
  @advertisement = AdMan::Advertisement.find(params[:id])

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

#updateObject

PUT /advertisements/1 PUT /advertisements/1.json



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/ad_man/advertisements_controller.rb', line 66

def update
  @advertisement = AdMan::Advertisement.find(params[:id])
  #@advertisement.keyword_id = params[:keyword_id]
  #@advertisement.priority = params[:priority]

  respond_to do |format|
    if @advertisement.update_attributes(params[:advertisement])
      format.html { redirect_to @advertisement, notice: 'Advertisement was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: "edit" }
      format.json { render json: @advertisement.errors, status: :unprocessable_entity }
    end
  end
end