Vikram
Vikram

Reputation: 3351

Use cookies value in model ruby on rails

How can I use cookies values in model.

I have a model to upload files using paperclip and added interpolate to pass cookie value. This cookie is set on login to user folder name.

I have an upload model to upload files and want to pass folder name to use in path in following code

has_attached_file :upload,
    :url => "/controllers/original/:basename.:extension",
    :path => "/files/uploads/:folder/:basename.:extension"

and this is how I use it in controller

@upload = Upload.new(params[:upload])

so I am not getting how to pass folder name to model, I tried to use interpolates but Local variables are not available there as well so I am stuck in here,

I am trying to do this because I can not get session or current user in model.

Upvotes: 3

Views: 2936

Answers (1)

dimakura
dimakura

Reputation: 7655

From documentation:

Cookies are read and written through ActionController#cookies.

If you need cookie's value in model, pass them from controller.

If you want a "dynamic" path for paperclip, here is the documentation for it.

Still I don't recommend you to save model data in cookie and rely on it.

Upvotes: 6

Related Questions