Skip to content

Instantly share code, notes, and snippets.

@jarodl
Created April 12, 2010 15:23
Show Gist options
  • Save jarodl/363678 to your computer and use it in GitHub Desktop.
Save jarodl/363678 to your computer and use it in GitHub Desktop.
# post.rb
class Post < ActiveRecord::Base
has_attached_file :upload
validates_presence_of :title
end
# posts_controller.rb
data = grab_data_for(@post)
file = StringIO.new(data)
file.class.class_eval { attr_accessor :original_filename }
file.original_filename = @post.to_filename
@post.upload = file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment