Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
How does rails determine the path from an object?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jason Waldrip  
View profile  
 More options Nov 17 2012, 12:29 am
From: Jason Waldrip <ja...@waldrip.net>
Date: Fri, 16 Nov 2012 21:29:14 -0800 (PST)
Local: Sat, Nov 17 2012 12:29 am
Subject: How does rails determine the path from an object?

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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Frederick Cheung  
View profile  
 More options Nov 17 2012, 4:09 am
From: Frederick Cheung <frederick.che...@gmail.com>
Date: Sat, 17 Nov 2012 01:08:49 -0800 (PST)
Local: Sat, Nov 17 2012 4:08 am
Subject: Re: How does rails determine the path from an object?

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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »