On Nov 17, 5:29 am, Jason Waldrip <ja...@waldrip.net> 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

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to