× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Rails might set empty array to nil

Chih-Wei Chang
Feb 05, 2016
<p>In some case, though I'm not sure if this is a bug or not, Rails might set the empty array in the params variable to nil.</p> <p>Just fix it like this:</p> <pre><code>params[:foo_ids] ||= [] if params.has_key?(:foo_ids) params.permit(foo_ids: [])</code></pre> <p> </p>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus