/
podcasts_controller.rb
99 lines (82 loc) · 2.47 KB
/
podcasts_controller.rb
1
2
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class PodcastsController < ApplicationController
before_filter :current_user
# GET /podcasts
# GET /podcasts.json
def index
@podcasts = Podcast.order("created_at DESC")
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @podcasts }
end
end
# GET /podcasts/1
# GET /podcasts/1.json
def show
@podcast = Podcast.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @podcast }
end
end
# GET /podcasts/new
# GET /podcasts/new.json
def new
@podcast = Podcast.new
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @podcast }
end
end
# GET /podcasts/1/edit
def edit
@podcast = Podcast.find(params[:id])
end
# POST /podcasts
# POST /podcasts.json
def create
@podcast = Podcast.new(params[:podcast])
respond_to do |format|
if @podcast.save
format.html { redirect_to @podcast, :notice => 'Podcast was successfully created.' }
format.json { render :json => @podcast, :status => :created, :location => @podcast }
else
format.html { render :action => "new" }
format.json { render :json => @podcast.errors, :status => :unprocessable_entity }
end
end
end
# PUT /podcasts/1
# PUT /podcasts/1.json
def update
@podcast = Podcast.find(params[:id])
respond_to do |format|
if @podcast.update_attributes(params[:podcast])
format.html { redirect_to @podcast, :notice => 'Podcast was successfully updated.' }
format.json { head :ok }
else
format.html { render :action => "edit" }
format.json { render :json => @podcast.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /podcasts/1
# DELETE /podcasts/1.json
def destroy
@podcast = Podcast.find(params[:id])
@podcast.destroy
respond_to do |format|
format.html { redirect_to podcasts_url }
format.json { head :ok }
end
end
def search
@keywords = "%" + params[:keywords] + "%"
if request.url.index('localhost')
conditions = ["poddesc LIKE ? or podname LIKE ?", @keywords, @keywords] unless @keywords == ""
else
conditions = ["poddesc ILIKE ? or podname ILIKE ?", @keywords, @keywords] unless @keywords == ""
end
@podcasts = Podcast.find(:all, :conditions => conditions, :order => 'created_at desc')
render :action => 'index'
end
end