Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:48:19+00:00 2026-06-15T06:48:19+00:00

I have a file model in my application that basically is a model with

  • 0

I have a file model in my application that basically is a model with only the paperclip file in it. I’m trying to upload some files using some nested forms, but everytime I save the file model, the actual file gets uploaded, but all the paperclip default columns remains nil. Here is the model I’m working with:

class Arquivo < ActiveRecord::Base

    attr_accessible :arquivo, :arquivo_file_name, :arquivo_file_size, :arquivo_content_type, :arquivo_updated_at

    has_one :aluno_documento

    attr_accessor :arquivo_file_name, :arquivo_file_size, :arquivo_content_type, :arquivo_updated_at

    has_attached_file :arquivo

    validates :arquivo_file_name, :presence => true
    validates_attachment_presence :arquivo
    validates_attachment_size :arquivo, :less_than => 1.megabyte, :if => :arquivo
    validates_attachment_content_type :arquivo, :content_type => 'application/pdf', :message => :invalid, :if => :arquivo
end

This is the params of the (multi level) nested form I’m building the Arquivo with:

{"arquivo"=>#<ActionDispatch::Http::UploadedFile:0x00000009176958 @original_filename="SGCAv3.7.pdf", @content_type="application/pdf", @headers="Content-Disposition: form-data; name=\"pessoa[alunos_attributes][0][aluno_documentos_attributes][0][arquivo_attributes][arquivo]\"; filename=\"SGCAv3.7.pdf\"\r\nContent-Type: application/pdf\r\n", @tempfile=#<File:/tmp/RackMultipart20121123-16651-se21y5>>}

This is what happens when I’m debugging in IRB:

ar = Arquivo.new(passing params above)
    => #<Arquivo id: nil, arquivo_file_name: nil, arquivo_content_type: nil, arquivo_file_size: nil, arquivo_updated_at: nil> 
ar.arquivo_file_name
    => "SGCAv3.7.pdf"
ar.arquivo_content_type
    => "application/pdf"
ar.save
    => true
ae = Arquivo.last
    => #<Arquivo id: 9, arquivo_file_name: nil, arquivo_content_type: nil, arquivo_file_size: nil, arquivo_updated_at: nil>
ae.valid?
    => false
ae.arquivo_file_name
    => nil

I looked and looked hoping to find that this was caused by something stupid, but I simply can’t understand how this can be happening, especially the part where the Arquivo object is actually being validated but all the fields remain empty?!?!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:48:20+00:00Added an answer on June 15, 2026 at 6:48 am

    I found the problem, and it actually had little to do with Paperclip:

    It turns out that my Arquivo model which has the paperclip attachment didn’t have the paperclip attributes tagged as “attr_accessible”. In Rails 3.2 you have a white list of attributes, and if an attribute isn’t on the white list (attr_accessible), you can’t assign it using a form (need more info on that). This is used to protect a user manually adding a field to a form and submitting more data than he should.

    Normally, Rails would throw a “Cannot mass-assign attributes: attr1, attr2, …” exception, but in this case it didn’t. I still don’t know if it was because of paperclip ignoring this error or because of the nesting level or both. Just adding the paperclip attributes to the white list worked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which binds a model and a file upload using the
We have an ancient application that basically duplicates a file explorer, outlook style application
I have these a coffeescript file for a model entree that just instanciates a
I have Course's model and the course consist of several file (stored only link
I've deployed a django-application, which basically works fine. The only problem I have is
I have settings.php file that I want to keep some constants in, like my
I'm using core data on an iPhone application. I have multiple persisntent stores that
I have an iOS application that uses a simple UIDocument model with a single
I have a view in my Django application that automatically creates an image using
i have an entity-model file (edmx) file which contains few tables and few stored

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.