Changeset 7520
- Timestamp:
- 09/20/07 23:34:07 (10 months ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/base.rb (modified) (1 diff)
- trunk/actionpack/lib/action_controller/mime_type.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r7516 r7520 1 1 *SVN* 2 3 * Added Mime::Type.register_alias for dealing with different formats using the same mime type [DHH]. Example: 4 5 class PostsController < ApplicationController 6 before_filter :adjust_format_for_iphone 7 8 def index 9 @posts = Post.find(:all) 10 11 respond_to do |format| 12 format.html # => renders index.html.erb and uses "text/html" as the content type 13 format.iphone # => renders index.iphone.erb and uses "text/html" as the content type 14 end 15 end 16 17 18 private 19 def adjust_format_for_iphone 20 if request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/iPhone/] 21 request.format = :iphone 22 end 23 end 24 end 25 26 * Added that render :json will automatically call .to_json unless it's being passed a string [DHH]. 2 27 3 28 * Autolink behaves well with emails embedded in URLs. #7313 [Jeremy McAnally, tarmo] trunk/actionpack/lib/action_controller/base.rb
r7473 r7520 827 827 828 828 elsif json = options[:json] 829 json = json.to_json unless json.is_a?(String) 829 830 json = "#{options[:callback]}(#{json})" unless options[:callback].blank? 830 831 response.content_type = Mime::JSON trunk/actionpack/lib/action_controller/mime_type.rb
r7438 r7520 53 53 end 54 54 55 def register(string, symbol, mime_type_synonyms = [], extension_synonyms = []) 55 # Registers an alias that's not usd on mime type lookup, but can be referenced directly. Especially useful for 56 # rendering different HTML versions depending on the user agent, like an iPhone. 57 def register_alias(string, symbol, extension_synonyms = []) 58 register(string, symbol, [], extension_synonyms, true) 59 end 60 61 def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], skip_lookup = false) 56 62 Mime.send :const_set, symbol.to_s.upcase, Type.new(string, symbol, mime_type_synonyms) 57 63 58 64 SET << Mime.send(:const_get, symbol.to_s.upcase) 59 65 60 ([string] + mime_type_synonyms).each { |string| LOOKUP[string] = SET.last } 66 ([string] + mime_type_synonyms).each { |string| LOOKUP[string] = SET.last } unless skip_lookup 61 67 ([symbol.to_s] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext] = SET.last } 62 68 end