Erik Gyepes
2007-Nov-20 20:21 UTC
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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mitchell James
2007-Nov-20 20:27 UTC
Re: How to rename image file before saving it using file_column?
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 Mitchell On Nov 20, 2007, at 3:21 PM, Erik Gyepes wrote:> > 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. > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Erik Gyepes
2007-Nov-20 20:47 UTC
Re: How to rename image file before saving it using file_col
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 MitchellThis 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''. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mitchell James
2007-Nov-20 20:51 UTC
Re: How to rename image file before saving it using file_col
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 Mitchell On Nov 20, 2007, at 3:47 PM, Erik Gyepes wrote:> > 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 Mitchell > > 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''. > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---