Filtering params

18 views
Skip to first unread message

Alfredo Barrero

unread,
Apr 24, 2014, 3:06:34 PM4/24/14
to rubyonra...@googlegroups.com
Good night,

Could anyone tell me how can I split this hash?

{"title"=>"sssssssss", "avatar"=>#<ActionDispatch::Http::UploadedFile:0x007fefd1104a28 @tempfile=#<Tempfile:/var/folders/_6/h2yz29bx1cs_swwr5vx6rl4r0000gn/T/RackMultipart20140424-10615-nfz0ta>, @original_filename="alf.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"photo[avatar]\"; filename=\"alf.jpg\"\r\nContent-Type: image/jpeg\r\n">}

I need to create a new Photo objet with that data. I can't use the normal way 'Photo.create(photo_params)' because I need to add the user.id to the photos table.

Below is the code that I'm using, but only the fields "title" and "user.id" are being saved in the table of each photo.

 @photo = Photo.create do |p|
      p.title = photo_params[:title]
      p.user_id = current_user.id
      print p.avatar_file_name = photo_params{attr_accessor :original_filename}
      p.avatar_content_type = photo_params[:content_type]
      p.avatar_file_size = photo_params[:avatar_file_size]
    end

Thanks & Regards

Alfredo.

Alfredo Barrero

unread,
Apr 24, 2014, 4:29:02 PM4/24/14
to rubyonra...@googlegroups.com
Ok solved.

@photo = Photo.new(photo_params)
@photo.title = photo_params[:title]
@photo.user_id = current_user.id

Thanks
Reply all
Reply to author
Forward
0 new messages