Reputation: 3264
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 question.
Upvotes: 2
Views: 361
Reputation: 83680
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
Upvotes: 2