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

module Rango
  module MessageMixin
    # The rails-style flash messages
    # @since 0.0.2
    # NOTE: it's important to include this mixin after ImplicitRendering mixin
    def self.included(controller)
      controller.class_eval do
        if self.method_defined?(:context)
          Rango.logger.debug("Extending #{self}#context by message")
          # This could be in the mixin itself, but we don't want
          # to define it if the context method doesn't exist, so
          # context.respond_to?(:context) as a detection of explicit
          # rendering mixin and similar can work. BTW the following
          # doesn't work with do/end syntax.
          include Module.new {
            def context
            def context
              super.merge!(message: self.message)
            end
          end
        end
      else
    def redirect(uri, options = Hash.new, status = 303, &block)
      # status, options = 303, status if status.is_a?(Hash)
      if options.respond_to?(:inject)
        # redirect "/post", error: "Try again"
    def message
      @message ||= (request.GET[:msg] || Hash.new)
    end

    # @since 0.0.2
    def redirect(url, options = Hash.new)
      url = [self.request.base_url.chomp("/"), url].join("/").chomp("/") unless url.match(/^http/)

      if options.respond_to?(:inject)
        # redirect "/post", error: "Try again"
        # ?msg[error]="Try again"
        url = options.inject(url) do |url, pair|
          type, message = pair
          url + "?msg[#{type}]=#{message}"
        end
      else
        # redirect "/post", "Try again"
        # ?msg="Try again"
        url.concat("?msg=#{options}")
      end

      self.status = 302
      self.headers["Location"] = URI.escape(url)
      return String.new
    end
  end
end
      else
        # redirect "/post", "Try again"
        # ?msg="Try again"
        uri.concat("?msg=#{options}")
      end
      super(uri, status)
    end
  end
end

<MSG> More DRY redirect

<DFF> @@ -19,6 +19,23 @@ module Rango
             def context
               super.merge!(message: self.message)
             end
+
+            def redirect(uri, status = 301, options = Hash.new)
+              status, options = 301, status if status.is_a?(Hash)
+              if options.respond_to?(:inject)
+                # redirect "/post", error: "Try again"
+                # ?msg[error]="Try again"
+                uri = options.inject(uri) do |uri, pair|
+                  type, message = pair
+                  uri + "?msg[#{type}]=#{message}"
+                end
+              else
+                # redirect "/post", "Try again"
+                # ?msg="Try again"
+                uri.concat("?msg=#{options}")
+              end
+              super(uri, status)
+            end
           end
         end
       else
@@ -29,27 +46,5 @@ module Rango
     def message
       @message ||= (request.GET[:msg] || Hash.new)
     end
-
-    # @since 0.0.2
-    def redirect(url, options = Hash.new)
-      url = [self.request.base_url.chomp("/"), url].join("/").chomp("/") unless url.match(/^http/)
-
-      if options.respond_to?(:inject)
-        # redirect "/post", error: "Try again"
-        # ?msg[error]="Try again"
-        url = options.inject(url) do |url, pair|
-          type, message = pair
-          url + "?msg[#{type}]=#{message}"
-        end
-      else
-        # redirect "/post", "Try again"
-        # ?msg="Try again"
-        url.concat("?msg=#{options}")
-      end
-
-      self.status = 302
-      self.headers["Location"] = URI.escape(url)
-      return String.new
-    end
   end
 end

More DRY redirect