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!
on 2012-11-17 06:30
on 2012-11-17 10:09
On Nov 17, 5:29am, 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
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.