Class: SimplePosts::PostsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/simple_posts/posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#atomObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/simple_posts/posts_controller.rb', line 16

def atom
  posts = @posts.blog_posts.reverse

  feed = RSS::Maker.make("atom") do |f|
    f.channel.title = SimplePosts.site_title
    f.channel.author = SimplePosts.site_author
    f.channel.about = SimplePosts::Engine.routes.url_helpers.posts_url
    f.channel.updated = posts[0].date.to_time

    posts.each do |post|
      f.items.new_item do |e|
        e.title = post.title
        e.link = SimplePosts::Engine.routes.url_helpers.post_url(id: post.name)
        e.id = SimplePosts::Engine.routes.url_helpers.post_url(id: post.id)
        e.updated = post.date.to_time
        e.pubDate = post.date.to_time
        e.content.content = post.render
      end
    end
  end

  render text: feed, content_type: 'application/atom+xml'
end

#indexObject



5
6
7
8
# File 'app/controllers/simple_posts/posts_controller.rb', line 5

def index
  @blog_posts = @posts.blog_posts.reverse
  render layout: SimplePosts.layout
end

#showObject

Raises:

  • (ActionController::RoutingError)


10
11
12
13
14
# File 'app/controllers/simple_posts/posts_controller.rb', line 10

def show
  @post = @posts.find(params[:id])
  raise ActionController::RoutingError.new('Not Found') unless @post
  render layout: SimplePosts.layout
end