<NME> rest_controller.rb
<BEF> # encoding: utf-8

require "rango/controller"
require "rango/mixins/conventional_rendering"

module Rango
  class RESTController < Controller
    include ConventionalRendering
    def self.object_name=(object_name)
    end

    def self.object_name
      @@object_name
    rescue NameError
      @@object_name = begin
        name = self.class.name
        name.split("::").last.snake_case
      end
    end

    # @api plugin
    def object_name
      self.class.object_name
    end

    def collection_name
      @@collection_name ||= @@object_name.to_s.pluralize
    end

    def self.named_route=(named_route)
      @@named_route = named_route
    end

    def self.named_route
      @@named_route
    rescue NameError
      @@named_route = begin
        name = self.class.name
        name.split("::").last.snake_case
      end
      end
    end

    # @api plugin
    def named_route
      self.class.named_route
    end

    # CRUD methods
    def index(&block)
      raise ArgumentError, "You have to provide a block" if block.nil?
      set_context_value(collection_name, block.call)
      autorender
    end

    def show(&block)
      raise ArgumentError, "You have to provide a block" if block.nil?
      set_context_value(collection_name, block.call)
      autorender
    end

    def new(&block)
      raise ArgumentError, "You have to provide a block" if block.nil?
      set_context_value(collection_name, block.call)
      autorender
    end

    def edit(&block)
      raise ArgumentError, "You have to provide a block" if block.nil?
      set_context_value(collection_name, block.call)
      autorender
    end

    def create(notice = "Created successfully", error = "Can't create", &block)
      raise ArgumentError, "You have to provide a block" if block.nil?
      object = block.call
      if object.save
        message[:notice] = notice
        redirect url(named_route, object)
      else
        message[:error] = error
        render_relative "show"
      end
    end

    def update(notice = "Updated successfully", error = "Can't update", &block)
      raise ArgumentError, "You have to provide a block" if block.nil?
      object = block.call
      if object.save
        message[:notice] = notice
        redirect url(named_route, object)
      else
        message[:error] = error
        render_relative "show"
      end
    end
  end
end

<MSG> CRUDMixin includes CRUD methods from RESTController now. Mixins FTW!

<DFF> @@ -1,10 +1,12 @@
 # encoding: utf-8
 
 require "rango/controller"
+require "rango/mixins/crud"
 require "rango/mixins/conventional_rendering"
 
 module Rango
   class RESTController < Controller
+    include CRUDMixin
     include ConventionalRendering
     def self.object_name=(object_name)
       @@object_name = object_name
@@ -41,58 +43,8 @@ module Rango
       end
     end
 
-    # @api plugin
     def named_route
       self.class.named_route
     end
-
-    # CRUD methods
-    def index(&block)
-      raise ArgumentError, "You have to provide a block" if block.nil?
-      set_context_value(collection_name, block.call)
-      autorender
-    end
-
-    def show(&block)
-      raise ArgumentError, "You have to provide a block" if block.nil?
-      set_context_value(collection_name, block.call)
-      autorender
-    end
-
-    def new(&block)
-      raise ArgumentError, "You have to provide a block" if block.nil?
-      set_context_value(collection_name, block.call)
-      autorender
-    end
-
-    def edit(&block)
-      raise ArgumentError, "You have to provide a block" if block.nil?
-      set_context_value(collection_name, block.call)
-      autorender
-    end
-
-    def create(notice = "Created successfully", error = "Can't create", &block)
-      raise ArgumentError, "You have to provide a block" if block.nil?
-      object = block.call
-      if object.save
-        message[:notice] = notice
-        redirect url(named_route, object)
-      else
-        message[:error] = error
-        render_relative "show"
-      end
-    end
-
-    def update(notice = "Updated successfully", error = "Can't update", &block)
-      raise ArgumentError, "You have to provide a block" if block.nil?
-      object = block.call
-      if object.save
-        message[:notice] = notice
-        redirect url(named_route, object)
-      else
-        message[:error] = error
-        render_relative "show"
-      end
-    end
   end
 end

CRUDMixin includes CRUD methods from RESTController now. Mixins FTW!