Class: AdMan::KeywordsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ad_man/keywords_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/ad_man/keywords_controller.rb', line 24

def create 
  @keyword = AdMan::Keyword.new(params[:keyword])
  respond_to do |format|
    if @keyword.save
      format.html { redirect_to advertisements_path, notice: "Keyword successfully created."}
      format.json { render json: @keyword, status: :created, location: @keyword }
    else
      format.html { render action: "new"}
      format.json { render json: @keyword.errors, status: :unprocessable_entity }
    end
  end        
end

#destroyObject



50
51
52
53
54
55
56
57
# File 'app/controllers/ad_man/keywords_controller.rb', line 50

def destroy 
  @keyword = AdMan::Keyword.find(params[:id])
  @keyword.destroy
  respond_to do |format|
    format.html { redirect_to advertisements_path }
    format.json { head :no_content }
  end
end

#editObject



20
21
22
# File 'app/controllers/ad_man/keywords_controller.rb', line 20

def edit
  @keyword = AdMan::Keyword.find(params[:id])
end

#indexObject



4
5
6
7
# File 'app/controllers/ad_man/keywords_controller.rb', line 4

def index
  @keywords = AdMan::Keyword.all
  respond_with @keywords
end

#newObject



15
16
17
18
# File 'app/controllers/ad_man/keywords_controller.rb', line 15

def new
  @keyword = AdMan::Keyword.new
  respond_with(@keyword)
end

#showObject



9
10
11
12
13
# File 'app/controllers/ad_man/keywords_controller.rb', line 9

def show
  @keyword = AdMan::Keyword.find(params[:id])
  @advertisements = AdMan::Advertisement.find_all_by_keyword_id(params[:id])
  @keywords = AdMan::Keyword.all
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/ad_man/keywords_controller.rb', line 37

def update 
  @keyword = AdMan::Keyword.find(params[:id])
  respond_to do |format|
    if @keyword.update_attributes(params[:keyword])
      format.html { redirect_to advertisements_path, notice: "Keyword successfully updated."}
      format.json { head :no_content }
    else 
      format.html { render action: "edit"}
      format.json { render json: @keyword.errors, status: :unprocessable_entity }
    end
  end
end