test/app/app/controllers/posts_controller.rb in focused_controller-0.1.0 vs test/app/app/controllers/posts_controller.rb in focused_controller-0.2.0

- old
+ new

@@ -1,59 +1,51 @@ -class PostsController +module PostsController class Action < ApplicationController end class Index < Action - def posts - @posts ||= Post.all - end - helper_method :posts + expose(:posts) { Post.all } end - class Singular < Action - def post - @post ||= begin - if params[:id] - Post.find(params[:id]) - else - Post.new(params[:post]) - end - end - end - helper_method :post + class Initializer < Action + expose(:post) { Post.new params[:post] } end - class Show < Singular + class New < Initializer end - class New < Singular - end - - class Edit < Singular - end - - class Create < Singular - def run + class Create < Initializer + def call if post.save redirect_to post, :notice => 'Post was successfully created.' else render :action => "new" end end end - class Update < Singular - def run + class Finder < Action + expose(:post) { Post.find params[:id] } + end + + class Show < Finder + end + + class Edit < Finder + end + + class Update < Finder + def call if post.update_attributes(params[:post]) redirect_to post, :notice => 'Post was successfully updated.' else render :action => "edit" end end end - class Destroy < Singular - def run + class Destroy < Finder + def call post.destroy redirect_to posts_url end end end