Class: Calliope::PostsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/calliope/controllers/posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#build_post(attributes = nil) ⇒ Object



42
43
44
# File 'lib/calliope/controllers/posts_controller.rb', line 42

def build_post(attributes = nil)
  current_blog.posts.build(attributes)
end

#createObject



24
25
26
27
28
# File 'lib/calliope/controllers/posts_controller.rb', line 24

def create
  @post = build_post(params[:post])
  @post.save
  respond_with(@post, :location => blog_post_url(current_blog.name, @post))
end

#current_blogObject



46
47
48
49
50
51
52
53
# File 'lib/calliope/controllers/posts_controller.rb', line 46

def current_blog
  unless @current_blog
    @current_blog = Blog.find_by_name(params[:name])
    raise ActiveRecord::RecordNotFound.new("Couldn't find blog with name #{params[:name]}") unless @current_blog
  end
  
  @current_blog
end

#destroyObject



36
37
38
39
40
# File 'lib/calliope/controllers/posts_controller.rb', line 36

def destroy
  @post = current_blog.posts.find(params[:id])
  @post.destroy
  respond_with(@post, :location => root_blog_url(current_blog.name))
end

#editObject



20
21
22
# File 'lib/calliope/controllers/posts_controller.rb', line 20

def edit
  @post = current_blog.posts.find(params[:id])
end

#indexObject



5
6
7
8
# File 'lib/calliope/controllers/posts_controller.rb', line 5

def index
  @posts = current_blog.posts.latest
  respond_with(@posts)
end

#newObject



15
16
17
18
# File 'lib/calliope/controllers/posts_controller.rb', line 15

def new
  @post = build_post
  respond_with(@post)
end

#showObject



10
11
12
13
# File 'lib/calliope/controllers/posts_controller.rb', line 10

def show
  @post = current_blog.posts.find(params[:id])
  respond_with(@post)
end

#updateObject



30
31
32
33
34
# File 'lib/calliope/controllers/posts_controller.rb', line 30

def update
  @post = current_blog.posts.find(params[:id])
  @post.update_attributes(params[:post])
  respond_with(@post, :location => blog_post_url(current_blog.name, @post))
end