Class: Calliope::PostsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Calliope::PostsController
- Defined in:
- lib/calliope/controllers/posts_controller.rb
Instance Method Summary collapse
- #build_post(attributes = nil) ⇒ Object
- #create ⇒ Object
- #current_blog ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
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 |
#create ⇒ Object
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_blog ⇒ Object
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 |
#destroy ⇒ Object
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 |
#edit ⇒ Object
20 21 22 |
# File 'lib/calliope/controllers/posts_controller.rb', line 20 def edit @post = current_blog.posts.find(params[:id]) end |
#index ⇒ Object
5 6 7 8 |
# File 'lib/calliope/controllers/posts_controller.rb', line 5 def index @posts = current_blog.posts.latest respond_with(@posts) end |
#new ⇒ Object
15 16 17 18 |
# File 'lib/calliope/controllers/posts_controller.rb', line 15 def new @post = build_post respond_with(@post) end |
#show ⇒ Object
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 |
#update ⇒ Object
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 |