Using params.require with form containing single paperclip file_field

I’m curious what’s the best way to avoid ActionController::ParameterMissing error using params.require with following form (from the tutorial):

<%= form_for @dashboard.new_photo_shout do |f| %>
  <%= f.file_field :image %>
  <%= f.submit "Shout!" %>
<% end %>

The problem is that you can submit the form without selecting a file, in which case you won’t get a photo_shout object in params, which will cause params.require(:photo_shout) to fail.

So what’s the recommended way to avoid crashing?

  • Rescue ActionController::ParameterMissing?
  • Include some sort of hidden field in the form to guarantee that you always have a photo_shout object?
  • Not use params.require? (What to use instead?)
  • Something else?

Thanks in advance!