Generating unique random URL's

67 views
Skip to first unread message

Scott Olmsted

unread,
Dec 28, 2009, 10:12:48 PM12/28/09
to ur...@googlegroups.com

My client wants to expose some report pages to users without them having to sign in. I suggested using a URL with a random slug, such as

  http://www.clientsite.com/report/3hf84hgiw

There are lots of such pages in the app now with the record id in the URL, accessible only if signed in.

I could add some code and a rake task to generate random slugs for existing records, or hack one of the many slug-generating plugins, but maybe someone has a better suggestion.

Thanks,

Scott

Chris Sund

unread,
Dec 28, 2009, 11:29:47 PM12/28/09
to Utah Ruby Users Group
Hey Scott,

I think adding a token through a rake command would be the easies. It
seems "aside from writing the rake task" this would be pretty simple.
Even the rake task should be pretty easy because it's simply a random
token. Something like this...


def generate_token
self.report_token ||= Digest::SHA1.hexdigest("--#{Time.now.to_s}--#
{id}--")
end


If you did a random url you would have to create a separate table to
keep track of the keys. It's only my opinion, but it seems adding a
field would be slightly less overhead in the long run.

I used random urls on this website "www.sliver.me". You can give it a
try, it's basically a url shortener mixed with a shadowbox to display
websites or images with style.

Thanks!

Chris

AJ ONeal

unread,
Dec 28, 2009, 11:42:36 PM12/28/09
to ur...@googlegroups.com
I used random urls on this website "www.sliver.me". You can give it a
try, it's basically a url shortener mixed with a shadowbox to display
websites or images with style.

In the spirit of being kind to users:

If you must prepend 'http://' and there's no other option, then why isn't it prepended for the user?

AJ ONeal

Chris Sund

unread,
Dec 28, 2009, 11:51:04 PM12/28/09
to Utah Ruby Users Group
Hey AJ,

I just haven't coded it yet. I wrote this site over the weekend and
didn't take the time to add that. I'll get right on it :-)

AJ ONeal

unread,
Dec 29, 2009, 12:06:26 AM12/29/09
to ur...@googlegroups.com
On Mon, Dec 28, 2009 at 11:51 PM, Chris Sund <ch...@silhouettesolutions.net> wrote:
Hey AJ,

I just haven't coded it yet. I wrote this site over the weekend and
didn't take the time to add that. I'll get right on it :-)

It just seemed odd that I can't use https (due to browser security it seems) and yet it was prompting me to enter http, which wasn't intuitive.

:D

Were you at all inspired by the discussion a week or so ago in this undertaking? Or did you have some particular business need to create silver.me?

Grady Player

unread,
Dec 29, 2009, 12:13:01 AM12/29/09
to ur...@googlegroups.com
I would write a custom route to process the obfuscated urls, and a
helper to make the links, but you would need to have a property in the
page attributes that allowed it to be viewed via the obfuscated URL...
Just an idea

Sent from my iPhone

On Dec 28, 2009, at 9:51 PM, Chris Sund
<ch...@silhouettesolutions.net> wrote:

> --
> Utah Ruby Users Group
> ur...@googlegroups.com
> http://groups.google.com/group/urug/
> - All meeting times and places can be found here.
>
> ** Please suffix your subject with "[JOB]" if your message is about
> job opportunities.

Chris Sund

unread,
Dec 29, 2009, 12:19:58 AM12/29/09
to ur...@googlegroups.com
Sliver.me was just a fun project to do / the brain child of a meeting I had with Eric Berry over lunch.  I wanted to create a screencast on creating short urls using Eric's teachmetocode.com site and thought I would use this as my sample site in the screencast. In any case I appreciate the feedback and feel free to use sliver.me, I will add functionality and refine it as time permits. 

 I should probably re-direct everyone back to Scott's original question so he can get some more advice. :-)

Thanks!
   
Chris Sund



--

Jake Mallory

unread,
Dec 29, 2009, 1:59:39 AM12/29/09
to ur...@googlegroups.com
So these reports are defined in the DB such that /report/1 will render report with ID # 1? If this is the case then do as you suggested by adding a code/slug field and store a hash/slug/randomness there if the report is to be exposed. (You could add functionality to allow the report creator to mark a report to be exposed. Otherwise create the code everytime the report is created) Make sure you have an action on the report controller that doesn't require authentication, /report/share/a62be921ff. If a report can be found render it. If you have links in the report you may want logic in the view to determine if they should be created or not.

There are a good number of ways to handle reports/reporting and this is one I just made up just for you. I like the idea of reports being bound to an instance rather than a definition such that each report could be rendered and stored then accessed or shared without having to be re-created. If the definition is stored then a newer version of the report can be created but each instance is unique, like a little snow flake. Where I work one of our apps has reports tacked on to it and asynchronously stores report definition, csv and html in S3 which we then redirect the user to. The report can be shared or viewed again without having to re-generate it, plus minimal resources are taken away from the primary role of the application server which is not to generate reports. (have you ever seen a ruby process when it's hungry, not a pretty site) Of course the report can be regenerated using the original form and definition

If you are doing a lot of reporting internal and external I'd recommend going to the next level with data warehousing. No need to stay on a wagon when a train is available.

Good luck

Scott Olmsted

unread,
Dec 29, 2009, 9:43:34 AM12/29/09
to ur...@googlegroups.com

Perhaps I should not have used 'report', it's just a view of some user data at this point. But the client may want these available as pdf's also, and in another project it was definitely easiest to render that at the same time as the page, stuff it as a blob into the database, and put up a link to download it. That site was very low traffic, so I removed old stored reports before rendering a new one, not even asynchronously.

Thanks to all for the ideas.

Scott


Reply all
Reply to author
Forward
0 new messages