why ?
require
works like params[:some_key]
, except it raises ActionController::ParameterMissing
when the value returned is blank.
This is handy because it allows, using rescue_from
, to render a 400: bad request
error in this case.
what to do ?
So you have to wrap your params so that when you call require(:choice)
you get a hash.
Unfortunately s3_upload_form
does not seem to support the same builder syntax as form_for
, that would allow you to do :
<%= form_for :s3_upload do |f| %>
<% f.file_field :file %>
<% end %>
resulting in a params hash like this :
{ s3_upload: {file: <SomeFile ...>} }
So my advice would simply be to drop the require
call, and to put :choice
along the other arguments passed to permit
.
If you want to still have the benefits of the require
method (that is, checking if a param is missing), you can always do something along the lines of :
def choice_params
params.permit(:foo, :bar, :baz).tap do |p|
p.each_key{ |k| p.require k }
end
end
this would raise an exception if any of the permitted parameters is missing.