Re: [Rails] Is it possible to include the username in an attachment file_name? Using Paperclip, Rails 3., Devise

32 views
Skip to first unread message
Message has been deleted

Scott Ribe

unread,
Oct 1, 2013, 5:51:03 PM10/1/13
to rubyonra...@googlegroups.com
On Oct 1, 2013, at 3:40 PM, Monserrat Foster <monse...@gmail.com> wrote:

> I think besides the obvious issue, it has to do bit

Well, no, it more likely has to do with the line of code pointed out in the error message ;-)

--
Scott Ribe
scott...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




Monserrat Foster

unread,
Oct 1, 2013, 6:02:00 PM10/1/13
to rubyonra...@googlegroups.com
lol. I meant, If i replace self.inventory.instance_write(:inventory_file_name, "#{:current_user}#{extension}") for 
self.inventory.instance_write(:inventory_file_name, "#{SecureRandom.hex(16)}#{extension}")
the error disappears but, the file_name doesn't change. it seems to be saving as :rails_root/tmp/uploaded_files/inventories/:basename_.:extension ignoring the self.inventory.instance_write(:inventory_file_name, "#{SecureRandom.hex(16)}#{extension}") line

Monserrat Foster

unread,
Oct 1, 2013, 6:27:40 PM10/1/13
to rubyonra...@googlegroups.com
I read this:


and it could work, but I have no idea how to do have a reference in your model to user table (say user_id), you can do sth like that attachment.instance.user_id

Could someone please give me an example? 

Scott Ribe

unread,
Oct 1, 2013, 7:03:28 PM10/1/13
to rubyonra...@googlegroups.com
On Oct 1, 2013, at 4:27 PM, Monserrat Foster <monse...@gmail.com> wrote:

> I read this:
>
> http://stackoverflow.com/questions/1146848/generating-a-unique-file-path-with-polymorphic-paperclip
>
> and it could work, but I have no idea how to do have a reference in your model to user table (say user_id), you can do sth like that attachment.instance.user_id
>
> Could someone please give me an example?
>
> On Tuesday, October 1, 2013 5:32:00 PM UTC-4:30, Monserrat Foster wrote:
> lol. I meant, If i replace self.inventory.instance_write(:inventory_file_name, "#{:current_user}#{extension}") for
> self.inventory.instance_write(:inventory_file_name, "#{SecureRandom.hex(16)}#{extension}")
> the error disappears but, the file_name doesn't change. it seems to be saving as :rails_root/tmp/uploaded_files/inventories/:basename_.:extension ignoring the self.inventory.instance_write(:inventory_file_name, "#{SecureRandom.hex(16)}#{extension}") line

Are you also removing the assignment to current_user when you do that? Because that's where the error comes from.

What is inventory_file_name? Why do you expect that setting it will actually set the file name?
Reply all
Reply to author
Forward
0 new messages