I have two model
User and UserAgent User has one UserAgent & UserAgent belongs to User And UserAgent using Paperclip to upload file to server Using this
has_attached_file :agreement,
:path => "#{Rails.root}/public/upload/new_agreements/:id/:basename.:extension"
This working fine.It is creating folders needed to upload the file.
But i need to create the folder like this
:path => "#{Rails.root}/public/upload/new_agreements/User:id/:basename.:extension"
That means I need to upload the file according to the User.id but not UserAgent.Id
Is there any way? You can ask questions if u don't understand the qu开发者_Python百科estion. Try that. I haven't test it, but you can modify it:
class UserAgent < ActiveRecord::Base
has_attached_file :file,
:path => lambda{ |a| "#{Rails.root}/public/upload/new_agreements/#{a.instance.user.id}/:id/:basename.:extension" }
end
精彩评论