File tree 8 files changed +79
-26
lines changed
8 files changed +79
-26
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ class FeedsController < ApplicationController
2
+ def show
3
+
4
+ posts = Rails . cache . fetch ( 'posts' , expires_in : 12 . hours ) do
5
+ Crowdblog ::Post . all_for_feed
6
+ end
7
+
8
+ events = Rails . cache . fetch ( 'events' , expires_in : 12 . hours ) do
9
+ Event . limit ( 15 )
10
+ end
11
+
12
+ @items = ( posts + events ) . sort_by ( &:updated_at ) . reverse
13
+
14
+ respond_to do | format |
15
+ format . xml { render layout : false }
16
+ format . rss { render layout : false }
17
+ end
18
+ end
19
+ end
Original file line number Diff line number Diff line change
1
+ xml . instruct! :xml , :version => "1.0"
2
+ xml . rss :version => "2.0" do
3
+ xml . channel do
4
+ xml . title "rails.mx"
5
+
6
+ @items . each do | item |
7
+ if item . class == Crowdblog ::Post
8
+
9
+ xml . item do
10
+ xml . title item . title
11
+ xml . description item . html_body
12
+ xml . pubDate item . published_at . to_s ( :rfc822 )
13
+ xml . link post_url ( *item . url_params )
14
+ end
15
+
16
+ else
17
+
18
+ xml . item do
19
+ xml . title item . name
20
+ xml . description item . description
21
+ xml . link event_url ( item . slug )
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
Original file line number Diff line number Diff line change 1
1
atom_feed do |feed |
2
- feed . title 'Rails Mx '
2
+ feed . title 'rails.mx '
3
3
feed . updated @items . first . updated_at if @items . first
4
4
@items . each do |item |
5
5
if item . class == Crowdblog ::Post
Original file line number Diff line number Diff line change 8
8
< meta name ="description " content ="Una comunidad de desarrolladores mexicanos e hispanohablantes.
9
9
Un punto de encuentro para compartir experiencias y mejores prácticas sobre el mundo de rails. ">
10
10
< meta name ="robots " content ="all " >
11
- <%= auto_discovery_link_tag ( :atom , '/atom.xml' ) %>
11
+ <%= auto_discovery_link_tag ( :atom , '/blog.xml' ) %>
12
+ <%= auto_discovery_link_tag ( :rss , '/blog.rss' ) %>
12
13
<%= favicon_link_tag "favicon-#{ ENV [ 'THEME' ] . downcase } .ico" %>
13
14
<%= stylesheet_link_tag "railsmx" %>
14
15
<%= javascript_include_tag "railsmx" %>
Original file line number Diff line number Diff line change 18
18
post "/contacto" => "contact_form#create" , as : :contact_form
19
19
20
20
21
- get "/atom" => 'atom_feeds#show'
21
+ get "/blog.(:format)" => 'feeds#show'
22
+
22
23
get "/:id" => "home#show" , as : :static
23
24
24
25
if Rails . env . test?
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ require "test_helper"
2
+
3
+ describe FeedsController do
4
+
5
+ describe "using xml as format" do
6
+ it "should get show" do
7
+ get :show , format : 'xml'
8
+ assert_response :success
9
+ end
10
+
11
+ it "should render xml" do
12
+ get :show , format : 'xml'
13
+ assert_template :show
14
+ end
15
+ end
16
+
17
+ describe "using rss as format" do
18
+ it "should get show" do
19
+ get :show , format : 'rss'
20
+ assert_response :success
21
+ end
22
+
23
+ it "should render rss" do
24
+ get :show , format : 'rss'
25
+ assert_template :show
26
+ end
27
+ end
28
+ end
You can’t perform that action at this time.
0 commit comments