Note that there are some explanatory texts on larger screens.

plurals
  1. PORails carrierwave - can't mass-assign protected attributes error
    primarykey
    data
    text
    <p>I'm trying to build a sample application where users can upload two different types of images to a model named Article. One type of images are images used in the content of the article, and the other is used as a thumbnail. Both types of images are handled by separate polymorphic models named ArticleImage and ArticleThumb.</p> <p>The problem is, whenever I try to upload a thumbnail, it gives me the "<strong>can't mass-protect protected attributes: :article_thumb</strong>" error. This error <em>does not</em> occur for the other type of image uploads.</p> <p><strong>Article</strong></p> <pre><code>class Article &lt; ActiveRecord::Base attr_accessible :title, :article_images_attributes, :article_thumbs_attributes has_many :comments, as: :commentable has_many :article_images, as: :attachable, dependent: :destroy has_many :article_thumbs, as: :attachable, dependent: :destroy accepts_nested_attributes_for :article_images, reject_if: :all_blank, allow_destroy: true accepts_nested_attributes_for :article_thumbs, allow_destroy: true belongs_to :user validates :title, presence: true, length: {maximum: 60} validates :user_id, presence: true validates :article_images, presence: true end </code></pre> <p><strong>ArticleImage</strong></p> <pre><code>class ArticleImage &lt; ActiveRecord::Base belongs_to :attachable, polymorphic: true attr_accessible :article_image mount_uploader :article_image, ArticleImageUploader end </code></pre> <p><strong>ArticleThumb</strong></p> <pre><code>class ArticleThumb &lt; ActiveRecord::Base belongs_to :attachable, polymorphic: true attr_accessible :article_thumb mount_uploader :article_thumb, ArticleThumbUploader end </code></pre> <p><strong>new.html.erb</strong></p> <pre><code>&lt;%= simple_nested_form_for @article, html: {multipart: true}, defaults: {required: false} do |f| %&gt; &lt;%= render 'shared/error_messages', object: @article %&gt; &lt;%= f.input :title %&gt; &lt;div class = "control-label"&gt; Image file upload &lt;/div&gt; &lt;%= f.simple_fields_for :article_images do |p| %&gt; &lt;%= p.file_field :article_image %&gt; &lt;%= p.link_to_remove 'Remove' %&gt; &lt;% end %&gt; &lt;%= f.link_to_add 'Add image', :article_images %&gt; &lt;span class="hint_end"&gt;Acceptable file formats: JPG, JPEG, GIF, PNG&lt;/span&gt; &lt;div class = "control-label"&gt; Thumbnail upload &lt;/div&gt; &lt;%= f.file_field :article_thumb %&gt; &lt;span class="hint"&gt; Automatically resized to 90x90 px. &lt;/span&gt; &lt;span class="hint"&gt; Default thumbnail is used if no thumbnail gets uploaded. &lt;/span&gt; &lt;span class="hint_end"&gt; Acceptable file formats: JPG, JPEG, GIF, PNG &lt;/span&gt; &lt;%= f.submit "Upload article" %&gt; &lt;% end %&gt; </code></pre> <p>I have a feeling this error only requires a very simple fix, but I just can't seem to figure it out. Any help would be appreciated.</p> <p>As a side note, I was wondering if it'd be efficient to mount all the different uploaders in a single polymorphic model so you don't have to create a different model every time you want to upload a different type of image/file. If you don't have much time you certainly don't need to bother answering this but any words on the matter are welcome!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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