1 class FeedController
< ApplicationController
4 @feeds = FeedItem
.select(:feed_name).distinct
7 format
.rss
{ render
:layout => false }
12 if FeedItem
::valid_feed_name?(params
[:feed_name])
13 @feed_name = params
[:feed_name]
14 @feed_items = FeedItem
.in_feed(@feed_name)
15 respond_to
do |format
|
17 flash
[:notice] = "No items in feed #{@feed_name}"
18 format
.html
{ redirect_to index_path
}
19 format
.rss
{ render
:layout => false }
22 format
.rss
{ render
:layout => false }
26 respond_to
do |format
|
27 flash
[:notice] = "Invalid feed name"
28 format
.html
{ redirect_to index_path
}
29 format
.rss
{ head
:not_found}
35 if FeedItem
::valid_feed_name?(params
[:feed_name])
36 item
= FeedItem
.in_feed(params
[:feed_name]).entitled(params
[:title]).take
38 if params
[:description].empty
?
47 respond_to
do |format
|
48 flash
[:notice] = "Invalid feed name"
49 format
.html
{ redirect_to index_path
}
50 format
.rss
{ head
:not_found }
58 private def create_item
59 item
= FeedItem
.new(:feed_name => params
[:feed_name],
60 :title => params
[:title],
61 :description => params
[:description])
63 flash
[:notice] = "Element #{params[:title]} created"
64 respond_to
do |format
|
65 format
.html
{ redirect_to
feed_path(params
[:feed_name]) }
66 format
.rss
{ head
:ok }
68 rescue ActiveRecord
::RecordInvalid => error
69 flash
[:notice] = "Element #{params[:title]} could not be created"
70 respond_to
do |format
|
71 format
.html
{ redirect_to
feed_path(params
[:feed_name]) }
72 format
.rss
{ head
:unprocessable_entity }
76 private def update_item(item
)
77 if item
.update_attribute(:description, params
[:description])
78 flash
[:notice] = "Element #{params[:title]} updated"
79 respond_to
do |format
|
80 format
.html
{ redirect_to
feed_path(params
[:feed_name]) }
81 format
.rss
{ head
:ok }
84 flash
[:notice] = "Element #{params[:title]} could not be updated"
85 respond_to
do |format
|
86 format
.html
{ redirect_to
feed_path(params
[:feed_name]) }
87 format
.rss
{ head
:unprocessable_entity }
92 private def destroy_item(item
)
94 flash
[:notice] = "Element #{params[:title]} deleted"
95 respond_to
do |format
|
96 format
.html
{ redirect_to
feed_path(params
[:feed_name]) }
97 format
.rss
{ head
:ok }
100 flash
[:notice] = "Element #{params[:title]} could not be deleted"
101 respond_to
do |format
|
102 format
.html
{ redirect_to
feed_path(params
[:feed_name]) }
103 format
.rss
{ head
:unprocessable_entity }