Skip to content

Commit

Permalink
newest topics rss.
Browse files Browse the repository at this point in the history
  • Loading branch information
chloerei committed Oct 30, 2011
1 parent 4c00428 commit 4307659
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
Binary file added app/assets/images/rss.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 11 additions & 3 deletions app/controllers/topics_controller.rb
Expand Up @@ -3,14 +3,22 @@ class TopicsController < ApplicationController
before_filter :find_topic, :only => [:show, :mark, :unmark]
before_filter :find_user_topic, :only => [:edit, :update]
respond_to :html, :js, :only => [:mark]
respond_to :html, :rss, :only => [:newest]

def index
@topics = Topic.active.page(params[:page])
end

def newest
@topics = Topic.order_by([[:created_at, :desc]]).page(params[:page])
render :index
respond_with(@topics) do |format|
format.html { render :index }
format.rss do
@page_title = 'Newest Topics'
@channel_link = newest_topics_path
render :index, :layout => false
end
end
end

def my
Expand Down Expand Up @@ -72,15 +80,15 @@ def mark
@topic.mark_by current_user
respond_with(@topic) do |format|
format.html { redirect_referrer_or_default @topic }
format.js { render :mark, :layout => false }
format.js { render :layout => false }
end
end

def unmark
@topic.unmark_by current_user
respond_with(@topic) do |format|
format.html { redirect_referrer_or_default @topic }
format.js { render :mark, :layout => false }
format.js { render :layout => false }
end
end

Expand Down
6 changes: 6 additions & 0 deletions app/views/topics/index.haml
Expand Up @@ -54,3 +54,9 @@

- else
= render :partial => 'shared/sidebar_login'
- if %w(newest).include?(action_name)
%section.box
%header Subscribe
- case action_name
- when
= link_to image_tag('rss.png'), newest_topics_path(:format => :rss)
25 changes: 25 additions & 0 deletions app/views/topics/index.rss.builder
@@ -0,0 +1,25 @@
xml.instruct!
xml.rss :version => "2.0" do
xml.channel do
xml.title @page_title
xml.link @channel_link
xml.description
xml.lastBuildDate @topics.first.created_at.to_s(:rfc822) if @topics.any?

@topics.each do |topic|
xml.item do
xml.title topic.title
xml.description format_text(topic.content)
xml.pubDate topic.created_at.to_s(:rfc822)
xml.author topic.user.profile.name
xml.link topic_url(topic, :page => topic.last_page, :anchor => topic.last_anchor)
xml.guid topic_url(topic)
if topic.tags.present?
topic.tags.each do |tag|
xml.category tag
end
end
end
end
end
end

0 comments on commit 4307659

Please sign in to comment.