How to enable Rack :: Test :: UploadedFile with strong parameters?

I am using the strong_parameters shortcut with Rails 3.2. To test the image upload process, I have an incoming mail request with parameters:

{"photo"=>{"image"=>#<Rack::Test::UploadedFile:0x000000069ce1f8 @content_type="image/png", @original_filename="test.png", @tempfile=#<Tempfile:/tmp/test.png20130420-9529-1xuka4v-1>>, "status"=>"approved", "in_use"=>false}, "controller"=>"member/photos", "action"=>"create"}

How to enable image attribute for assignment? I tried;

params.require(:photo).permit(:image)

but he does not work and speaks Validation failed: Image can't be blank.

When I resolve all parameters with params.require(:photo).permit!, it works fine.

+5
source share
1 answer

From http://api.rubyonrails.org/classes/ActionController/Parameters.html

PERMITTED_SCALAR_TYPES = [String, Symbol, NilClass, Numeric, TrueClass, FalseClass, Date, Time, StringIO, IO, ActionDispatch:: Http:: UploadedFile, Rack:: Test:: UploadedFile]

:

params.require(:photo).permit(:image)

Rails 4.1.1

+1

All Articles