readruby (owner)

Revisions

gist: 74701 Download_button fork
public
Public Clone URL: git://gist.github.com/74701.git
Embed All Files: show embed
/lib/paperclip/attachment.rb #
1
2
3
4
5
6
7
8
9
10
11
12
# Source:
# http://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/attachment.rb
 
# Writes the attachment-specific attribute on the instance. For example,
# instance_write(:file_name, "me.jpg") will write "me.jpg" to the instance's
# "avatar_file_name" field (assuming the attachment is called avatar)
def instance_write(attr, value)
    setter = :"#{name}_#{attr}="
    responds = instance.respond_to?(setter)
    self.instance_variable_set("@_#{setter.to_s.chop}", value)
    instance.send(setter, value) if responds || attr.to_s == "file_name"
end