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! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/bxS3Y1M_g_AJ. For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2012-Nov-17 09:08 UTC
Re: How does rails determine the path from an object?
On Nov 17, 5:29 am, Jason Waldrip <ja...-ZCXSCX6dGh/R7s880joybQ@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.