root/lang/ruby/pritter/vendor/rails/actionpack/lib/action_controller/response.rb @ 5644

Revision 5644, 1.2 kB (checked in by nakamud, 6 years ago)

lang/ruby/pritter: freezed gems to ease installation

Line 
1module ActionController
2  class AbstractResponse #:nodoc:
3    DEFAULT_HEADERS = { "Cache-Control" => "no-cache" }
4    attr_accessor :body, :headers, :session, :cookies, :assigns, :template, :redirected_to, :redirected_to_method_params, :layout
5
6    def initialize
7      @body, @headers, @session, @assigns = "", DEFAULT_HEADERS.merge("cookie" => []), [], []
8    end
9
10    def content_type=(mime_type)
11      @headers["Content-Type"] = charset ? "#{mime_type}; charset=#{charset}" : mime_type
12    end
13   
14    def content_type
15      content_type = String(@headers["Content-Type"]).split(";")[0]
16      content_type.blank? ? nil : content_type
17    end
18   
19    def charset=(encoding)
20      @headers["Content-Type"] = "#{content_type || "text/html"}; charset=#{encoding}"
21    end
22   
23    def charset
24      charset = String(@headers["Content-Type"]).split(";")[1]
25      charset.blank? ? nil : charset.strip.split("=")[1]
26    end
27
28    def redirect(to_url, permanently = false)
29      @headers["Status"]   = "302 Found" unless @headers["Status"] == "301 Moved Permanently"
30      @headers["Location"] = to_url
31
32      @body = "<html><body>You are being <a href=\"#{to_url}\">redirected</a>.</body></html>"
33    end
34  end
35end
Note: See TracBrowser for help on using the browser.