Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My other answer was mostly wrong - new answer. </p> <p>in your params hash, :filename is not associated with another hash, it is associated with an ActiveDispatch::Http::UploadedFile object. Your last code line:</p> <pre><code>def screenshot_params params.require(:screenshot).permit(:title, assets_attributes: :filename) </code></pre> <p>is actually correct, however, the filename attribute is not being allowed since it is not one of the permitted <a href="https://github.com/rails/rails/blob/16e0c8816c4c8a9fb5292278bf5753b026c1105c/actionpack/lib/action_controller/metal/strong_parameters.rb#L362">scalar types</a>. If you open up a console, and initialize a params object in this shape:</p> <pre><code>params = ActionController::Parameters.new screenshot: { title: "afa", assets_attributes: {"0" =&gt; {filename: 'a string'}}} </code></pre> <p>and then run it against your last line:</p> <pre><code>p = params.require(:screenshot).permit(:title, assets_attributes: :filename) # =&gt; {"title" =&gt; "afa", "assets_attributes"=&gt;{"0"=&gt;{"filename"=&gt;"abc"}}} </code></pre> <p>However, if you do the same against a params hash with the uploaded file, you get </p> <pre><code>upload = ActionDispatch::Http::UplaodedFile.new tempfile: StringIO.new("abc"), filename: "abc" params = ActionController::Parameters.new screenshot: { title: "afa", assets_attributes: {"0" =&gt; {filename: upload}}} p = params.require(:screenshot).permit(:title, assets_attributes: :filename) # =&gt; {"title" =&gt; "afa", "assets_attributes"=&gt;{"0"=&gt;{}}} </code></pre> <p>So, it is probably worth a bug or pull request to Rails, and in the meantime, you will have to directly access the filename parameter using the raw <code>params</code> object:</p> <pre><code>params[:screenshot][:assets_attributes]["0"][:filename] </code></pre>
 

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