Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 4.0 Strong Parameters nested attributes with a key that points to a hash
    text
    copied!<p>I was playing around with Rails 4.x beta and trying to get nested attributes working with carrierwave. Not sure if what I'm doing is the right direction. After searching around, and then eventually looking at the rails source and strong parameters I found the below notes. </p> <blockquote> <pre><code># Note that if you use +permit+ in a key that points to a hash, # it won't allow all the hash. You also need to specify which # attributes inside the hash should be whitelisted. </code></pre> </blockquote> <p><a href="https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/strong_parameters.rb">https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/strong_parameters.rb</a></p> <p>So its saying you have to specify every single every single attribute within the has, I tried the following:</p> <p>Param's example:</p> <pre><code>{"utf8"=&gt;"✓", "authenticity_token"=&gt;"Tm54+v9DYdBtWJ7qPERWzdEBkWnDQfuAQrfT9UE8VD=", "screenshot"=&gt;{ "title"=&gt;"afs", "assets_attributes"=&gt;{ "0"=&gt;{ "filename"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x00000004edbe40 @tempfile=#&lt;File:/tmp/RackMultipart20130123-18328-navggd&gt;, @original_filename="EK000005.JPG", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"screenshot[assets_attributes][0][filename]\"; filename=\"EK000005.JPG\"\r\nContent-Type: image/jpeg\r\n"&gt; } } }, "commit"=&gt;"Create Screenshot"} </code></pre> <p>Controller</p> <pre><code>def screenshot_params params.require(:screenshot).permit(:title, :assets_attributes =&gt; [:filename =&gt; [:@tempfile,:@original_filename,:@content_type,:@headers] </code></pre> <p>The above isn't "working" (its not triggering carrierwave) however I am no longer getting errors (Unpermitted parameters: filename) when using the standard nested examples I found ex:</p> <pre><code>def screenshot_params params.require(:screenshot).permit(:title, assets_attributes: :filename) </code></pre> <p>If anyone could help it would be great. I was not able to find a example with nested with a key that points to a hash.</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