Associate a URL with a resource within my application

Posted by Horace Loeb on Stack Overflow See other posts from Stack Overflow or by Horace Loeb
Published on 2010-05-07T21:14:54Z Indexed on 2010/05/07 21:18 UTC
Read the original article Hit count: 109

Filed under:

When I visit http://my-application.com/posts/1 in my browser, Rails knows I'm looking for the Post with id = 1. How can I get my application to do this internally? I.e., I'd like a function (call it associate_with_resource) that takes a string containing a URL as its input and outputs the associated resource. For example:

>> associate_with_resource('http://my-application.com/posts/1')
=> #<Post id: 1, ... >

(I'd like to be able to use associate_with_resource throughout my application though -- not only in the console)

© Stack Overflow or respective owner

Related posts about ruby-on-rails