Im debugging my rails app with an iOS client. Its a photo sharing and uploading app that Im following from
I finished the client part where the photos show up around the cleint. The next part which includes uploading images to the server from the client is where there are errors happening. Im using a ‘puts @photos’ statement in the controller to see the variable created after the upload.
This is the error that been thrown after a photo is uploaded from the device
19:07:06 web.1 | Started POST "/photos" for 127.0.0.1 at 2012-09-11 19:07:05 -0700
19:07:06 web.1 | Connecting to database specified by database.yml
19:07:06 web.1 | Processing by PhotosController#create as JSON
19:07:06 web.1 | Parameters: {"photo%5Blat%5D"=>"37.785834",
"photo%5Blng%5D"=>"-122.406417", "photo"=>{"image"=>#
<ActionDispatch::Http::UploadedFile:0x007ff3cf0a3870
@original_filename="image.jpg", @content_type="image/jpeg",
@headers="Content-Disposition: form-data; name=\"photo[image]\";
filename=\"image.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#
<File:/var/folders/dh/1k2rdp_51yd2k43xzkc2pmdh0000gn/T/RackMultipart20120911-22662-1walqgi>>}}
19:07:06 web.1 | Completed 500 Internal Server Error in 55ms
19:07:06 web.1 | ActiveModel::MassAssignmentSecurity::Error (Can't mass-assign protected attributes: image):
19:07:06 web.1 | app/controllers/photos_controller.rb:51:in `new'
19:07:06 web.1 | app/controllers/photos_controller.rb:51:in `create'
You’re getting a mass-assignment error on the
imageattribute of thePhotomodel. Just add:somewhere in the model and it should work. See the documentation for details.