On Dec 18 2008, 5:15 pm, Jonathan Yurek <
jyu...@thoughtbot.com> wrote:
> If you're generating and saving therandomname of the file in the
> database you can add your own interpolation which can be used in urls
> and paths.
I'd been doing this with a before_create callback instead:
class Photo < ActiveRecord::Base
has_attached_file :image # ...
before_create :randomize_file_name
def randomize_file_name
extension = self.image_file_name.scan(/\.\w+$/).to_s.downcase
self.image_file_name = "#{CGI::Session.generate_unique_id}#
{extension}"
end
end
Not sure if this is better than the interpolation method, but it seems
to work well enough. Let me know if this stands out as a bad
technique, though!
- Trevor