Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6750

Show
Ignore:
Timestamp:
05/17/07 20:48:47 (1 year ago)
Author:
david
Message:

Added url_for usage on render :location, which allows for record identification [DHH] (still need to figure out why that test doesnt pass, seems like a test issue)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r6740 r6750  
    11*SVN* 
     2 
     3* Added url_for usage on render :location, which allows for record identification [DHH]. Example: 
     4 
     5    render :xml => person, :status => :created, :location => person 
     6   
     7  ...expands the location to person_url(person). 
    28 
    39* Introduce the request.body stream. Lazy-read to parse parameters rather than always setting RAW_POST_DATA. Reduces the memory footprint of large binary PUT requests.  [Jeremy Kemper] 
  • trunk/actionpack/lib/action_controller/base.rb

    r6736 r6750  
    776776 
    777777        if location = options[:location] 
    778           response.headers["Location"] = location 
     778          response.headers["Location"] = url_for(location) 
    779779        end 
    780780 
  • trunk/actionpack/test/controller/new_render_test.rb

    r6574 r6750  
    11require File.dirname(__FILE__) + '/../abstract_unit' 
    22 
    3 silence_warnings { Customer = Struct.new("Customer", :name) } 
     3silence_warnings { Customer = Struct.new(:name, :id) } 
     4 
     5class CustomersController < ActionController::Base 
     6end 
    47 
    58module Fun 
     
    261264  def render_with_location 
    262265    render :xml => "<hello/>", :location => "http://example.com", :status => 201 
     266  end 
     267   
     268  def render_with_object_location 
     269    customer = Customer.new("Some guy", 1) 
     270    render :xml => "<customer/>", :location => customer_url(customer), :status => :created 
    263271  end 
    264272 
     
    767775    assert_equal "<i-am-xml/>", @response.body 
    768776  end 
     777   
     778  def test_rendering_with_object_location_should_set_header_with_url_for 
     779    ActionController::Routing::Routes.draw do |map| 
     780      map.resources :customers 
     781      map.connect ':controller/:action/:id' 
     782    end 
     783     
     784    get :render_with_object_location 
     785    assert_equal "http://test.host/customers/1", @response.headers["Location"] 
     786  end 
    769787end