# How does rails determine the path from an object?

**URL:** <https://www.ruby-forum.com/t/how-does-rails-determine-the-path-from-an-object/224569>\
**Category:** Rails\
**Created:** [November 17, 2012, 6:30am UTC](https://www.ruby-forum.com/t/how-does-rails-determine-the-path-from-an-object/224569 "2012-11-17T06:30:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [November 17, 2012, 6:30am UTC](https://www.ruby-forum.com/t/how-does-rails-determine-the-path-from-an-object/224569/1 "2012-11-17T06:30:45Z")

</div>

I have been working on implementing my own ORM. And I was wondering how  
the  
rails path helper extracts the ID from the object. For example how would  
I  
make this work for my ORM?

```
@contact = Contact.first
contact_path(@contact)

```

Any help would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![jasonwold](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e36b37/32.png) [@jasonwold](https://www.ruby-forum.com/u/jasonwold)\
**Post date:** [November 17, 2012, 10:09am UTC](https://www.ruby-forum.com/t/how-does-rails-determine-the-path-from-an-object/224569/2 "2012-11-17T10:09:48Z")

</div>

On Nov 17, 5:29am, Jason W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have been working on implementing my own ORM. And I was wondering how the  
> rails path helper extracts the ID from the object. For example how would I  
> make this work for my ORM?
> 
> @contact = Contact.first  
> contact\_path(@contact)
> 
> Any help would be greatly appreciated!

These end up calling polymorphic\_path and the magic term here is  
active model. Active model is 2 things: reusable modules dealing with  
things such as validations, dirty attributes etc. and a protocol that  
classes should conform to. It’s the latter you’re interested in. There  
are only a handful of methods you have to implement, including (from  
memory) to\_param, new\_record? And a few others. There’s also an  
ActiveModel::Lint module that tests that your implementations of these  
primitives are valid. Once you have that you should be able to use the  
URL helpers, do stuff such as form\_for(@contact) and so on

Fred
