Permalink
Browse files

Improve the test app controller

This version is more succinct and IMO a better example of Focused
Controller usage.
  • Loading branch information...
1 parent e6e13e7 commit 6b9365a425d978fec2ca9a61b8b813f985208cac @jonleighton committed Sep 2, 2012
Showing with 7 additions and 16 deletions.
  1. +7 −16 test/app/app/controllers/posts_controller.rb
@@ -1,19 +1,13 @@
module PostsController
- class Action < ApplicationController
- end
-
- class Index < Action
+ class Index < ApplicationController
expose(:posts) { Post.all }
end
- class Initializer < Action
+ class New < ApplicationController
expose(:post) { Post.new params[:post] }
end
- class New < Initializer
- end
-
- class Create < Initializer
+ class Create < New
def call
if post.save
redirect_to post, :notice => 'Post was successfully created.'
@@ -23,17 +17,14 @@ def call
end
end
- class Finder < Action
+ class Show < ApplicationController
expose(:post) { Post.find params[:id] }
end
- class Show < Finder
- end
-
- class Edit < Finder
+ class Edit < Show
end
- class Update < Finder
+ class Update < Edit
def call
if post.update_attributes(params[:post])
redirect_to post, :notice => 'Post was successfully updated.'
@@ -43,7 +34,7 @@ def call
end
end
- class Destroy < Finder
+ class Destroy < Edit
def call
post.destroy
redirect_to posts_url

0 comments on commit 6b9365a

Please sign in to comment.