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)