Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 4 strong parameters param not found error with carrierwave
    text
    copied!<p>I'm having trouble with carrierwave and rails 4 strong parameters. I have a very simple model with a carrier wave upload button. I'd like to show an error message if someone submits the upload form without choosing a file to upload. </p> <p>Right now, I get a <code>param not found:photo</code> error with this message:</p> <pre><code> # Never trust parameters from the scary internet, only allow the white list through. def photo_params params.require(:photo).permit(:image) end </code></pre> <p>This error is happening because Rails 4's strong parameters is requiring that the image parameter be present to submit the form, but it's not there because the user hasn't selected an image.</p> <p>I can't figure out a way to work around this and have it redirect to the same action and display an error message.</p> <p>Is there a way to do this with strong parameters?</p> <p>Here's the development log when I try to use the form without a photo selected: <a href="https://gist.github.com/leemcalilly/09b6166ce1af6ca6c833">https://gist.github.com/leemcalilly/09b6166ce1af6ca6c833</a></p> <p>And here's the development log when I choose a photo and it uploads successfully: <a href="https://gist.github.com/leemcalilly/1f1e584f56aef15e7af1">https://gist.github.com/leemcalilly/1f1e584f56aef15e7af1</a></p> <p>Other relevant files: * models/photo.rb - <a href="https://gist.github.com/leemcalilly/95c54a5df4e4ee6518da">https://gist.github.com/leemcalilly/95c54a5df4e4ee6518da</a> * controllers/photos_controller.rb - <a href="https://gist.github.com/leemcalilly/c0723e6dc5478b0f914d">https://gist.github.com/leemcalilly/c0723e6dc5478b0f914d</a> * uploaders/image_uploader.rb - <a href="https://gist.github.com/leemcalilly/5e43f6524734991773ae">https://gist.github.com/leemcalilly/5e43f6524734991773ae</a> * views/photos/index.html.erb - <a href="https://gist.github.com/leemcalilly/a8c4c808e5e8a802933b">https://gist.github.com/leemcalilly/a8c4c808e5e8a802933b</a> * views/photos/_form.html.erb - <a href="https://gist.github.com/leemcalilly/cd0fd518c1b47d9bfb62">https://gist.github.com/leemcalilly/cd0fd518c1b47d9bfb62</a> * initializers/carrierwaver.rb - <a href="https://gist.github.com/leemcalilly/49e04fa1dda891dd108b">https://gist.github.com/leemcalilly/49e04fa1dda891dd108b</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload