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

Changeset 7764

Show
Ignore:
Timestamp:
10/07/07 02:13:51 (1 year ago)
Author:
nzkoz
Message:

Add Base#to_param to Active Resource that quacks like ActiveRecord. Closes #9557 [bradediger]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activeresource/lib/active_resource/base.rb

    r7719 r7764  
    549549    def id=(id) 
    550550      attributes[self.class.primary_key] = id 
     551    end 
     552 
     553    # Allows ActiveResource objects to be used as parameters in ActionPack URL generation. 
     554    def to_param 
     555      id && id.to_s 
    551556    end 
    552557 
  • trunk/activeresource/test/base_test.rb

    r7719 r7764  
    445445    assert xml.include?('<id type="integer">1</id>') 
    446446  end 
     447 
     448  def test_to_param_quacks_like_active_record 
     449    new_person = Person.new 
     450    assert_nil new_person.to_param 
     451    matz = Person.find(1) 
     452    assert_equal '1', matz.to_param 
     453  end 
    447454end