Ruby on Rails
Thursday, April 24, 2014
Ok solved.
@photo = Photo.new(photo_params)
@photo.title = photo_params[:title]
@photo.user_id = current_user.id
Thanks
El jueves, 24 de abril de 2014 21:06:34 UTC+2, Alfredo Barrero escribió:
-- @photo = Photo.new(photo_params)
@photo.title = photo_params[:title]
@photo.user_id = current_user.id
Thanks
El jueves, 24 de abril de 2014 21:06:34 UTC+2, Alfredo Barrero escribió:
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.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2174a955-2378-406a-99fc-5805d575aa12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment