How to rename image file before saving it using file_column?

Hello,

I’m playing with the file_column plugin and I would like to rename the
file when uploading it and before saving it to DB. I’ve tried it with
before_create method in my model and also in the controller with the
following code:

@picture = Picture.new(params[:picture])
@picture.filename = ‘newname’

Which doesn’t worked.

How it could be done (if it is possible)?

Thanks.

Don’t know if this is a bad practice, but how about substituting the
param value before sending it to the model?

params[:picture].merge!(:filename => ‘newname’)
@picture = Picture.create(params[:picture])


James M.

Mitchell James wrote:

Don’t know if this is a bad practice, but how about substituting the
param value before sending it to the model?

params[:picture].merge!(:filename => ‘newname’)
@picture = Picture.create(params[:picture])


James M.

This also doesn’t worked. I’m getting the same as with my ‘solution’:

Do not know how to handle a string with value ‘newname’ that was passed
to a file_column. Check if the form’s encoding has been set to
‘multipart/form-data’.

That’s right, you can’t set a string into a binary field.

Read this:
http://wiki.rubyonrails.org/rails/pages/HowToUseFileColumn

… and pay attention to “:multipart => true”


James M.