Changeset 8956
- Timestamp:
- 02/29/08 18:09:23 (4 months ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_view/base.rb (modified) (1 diff)
- trunk/actionpack/test/controller/new_render_test.rb (modified) (1 diff)
- trunk/actionpack/test/fixtures/test/greeting.js.rjs (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r8883 r8956 1 1 *SVN* 2 3 * Added that requests with JavaScript as the priority mime type in the accept header and no format extension in the parameters will be treated as though their format was :js when it comes to determining which template to render. This makes it possible for JS requests to automatically render action.js.rjs files without an explicit respond_to block [DHH] 2 4 3 5 * Tests for distance_of_time_in_words with TimeWithZone instances. Closes #10914 [ernesto.jimenez] trunk/actionpack/lib/action_view/base.rb
r8805 r8956 345 345 346 346 # symbolized version of the :format parameter of the request, or :html by default. 347 # 348 # EXCEPTION: If the :format parameter is not set, the Accept header will be examined for 349 # whether it contains the JavaScript mime type as its first priority. If that's the case, 350 # it will be used. This ensures that Ajax applications can use the same URL to support both 351 # JavaScript and non-JavaScript users. 347 352 def template_format 348 353 return @template_format if @template_format 349 format = controller && controller.respond_to?(:request) && controller.request.parameters[:format] 350 @template_format = format.blank? ? :html : format.to_sym 354 355 if controller && controller.respond_to?(:request) 356 parameter_format = controller.request.parameters[:format] 357 accept_format = controller.request.accepts.first 358 359 case 360 when parameter_format.blank? && accept_format != :js 361 @template_format = :html 362 when parameter_format.blank? && accept_format == :js 363 @template_format = :js 364 else 365 @template_format = parameter_format.to_sym 366 end 367 else 368 @template_format = :html 369 end 351 370 end 352 371 trunk/actionpack/test/controller/new_render_test.rb
r8822 r8956 551 551 end 552 552 553 def test_render_with_default_from_accept_header 554 @request.env["HTTP_ACCEPT"] = "text/javascript" 555 get :greeting 556 assert_equal "$(\"body\").visualEffect(\"highlight\");", @response.body 557 end 558 553 559 def test_render_rjs_with_default 554 560 get :delete_with_js