ruby on rails - Paperclip - how to access saved file -
every one! using paperclip upload files
class model include mongoid::document include mongoid::paperclip has_many :myfiles end class myfile include mongoid::document include mongoid::paperclip belongs_to :model has_mongoid_attached_file :file, :path => ":rails_root/public/uploads/:class/:id/:basename.:extension", end
my question how access uploaded file after saved? tried:
@model.myfiles.first.path @model.myfiles.first.url
it gives error:
nomethoderror: undefined method `path' #<myfile:0x007fd22b336f80>
thank much help!
try :)
@model.myfiles.first.file.path @model.myfiles.first.file.url
you can delegate fields if want
class myfile include mongoid::document include mongoid::paperclip belongs_to :model has_mongoid_attached_file :file, :path => ":rails_root/public/uploads/:class/:id/:basename.:extension" delegate :url, :path, to: :file, allow_nil: true, prefix: false end
then can use
@model.myfiles.first.path @model.myfiles.first.url
ruby-on-rails paperclip
No comments:
Post a Comment