Friday, July 20, 2012

[Rails] Re: Encode URL for a file upload

Walter Davis wrote in post #1065538:


> match '/:slug', :to => 'uploaded_files#show'
>
> That should do the trick.
>
> Here's a way to make a very terse code for your URL:
>
> def set_slug
> code = Array.new(7) { (('A'..'Z').to_a + (0..9).to_a)[rand(36)]
> }.join.to_s
> if UploadedFile.find_by_slug(code)
> return self.set_slug()
> else
> self.slug = code
> end
> end
>
> Call it in an after_create.
>
> Walter

Thanks a lot. It is working :) cheers....

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate