Retrieving ID from a POST URI

4 views
Skip to first unread message

bradigan

unread,
Nov 24, 2011, 7:50:27 PM11/24/11
to Ruby on Rails: Talk
To note, I only have the URI in a string as its from a POST from an
external API as JSON Data.
Basically I need this:

http://www.someapp.com/events/12345

I just need the 12345

Obviously, params[:id] won't work so I'm not sure how to get this. I
tried this:

url = data['referring_site']
event_id = CGI::parse(URI::parse(url).query)

But it didn't work.
Where the referring_site was the URL in question.
Thanks
Brad

JGW Maxwell

unread,
Nov 24, 2011, 8:29:22 PM11/24/11
to rubyonra...@googlegroups.com
Is there anything wrong with:

data['referring_site'].split("/").last 

Which will give you what you are looking for, assuming that is the limit of your URL?

bradigan

unread,
Nov 24, 2011, 10:09:02 PM11/24/11
to Ruby on Rails: Talk
Beauty!!!! Thats it.
Thank you.
Knew it was a string call, just not sure which one. Especially coming
from the PHP world.
Thanks again.
B

Robert Walker

unread,
Nov 28, 2011, 6:51:47 AM11/28/11
to rubyonra...@googlegroups.com
bradigan wrote in post #1033619:

> To note, I only have the URI in a string as its from a POST from an
> external API as JSON Data.
> Basically I need this:
>
> http://www.someapp.com/events/12345

For what it's worth, a request to that URL should be sent using the HTTP
PUT method. If I'm not mistaken Rails should then automatically provide
"12345" in params[:id].

But, the provided solutions should work for your needs.

--
Posted via http://www.ruby-forum.com/.

Reply all
Reply to author
Forward
0 new messages