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 7920283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:09:21+00:00 2026-06-03T16:09:21+00:00

I’m working on a paperclip upload system where I have a User who has

  • 0

I’m working on a paperclip upload system where I have a User who has many Uploads which in turn have many Upload_Images relationship.

Due to the nature of how my system is meant to work, a User is created once and then has uploads added in the future and Upload records need to be created in the User controllers update action. Originally it was just the Upload record that needed to be created, but I had to extend the functionality to include an Upload_image. As it stands, the Upload record is created, but not the upload_image.

He’s the params hash for where the Update method is getting called after the New upload form (with upload image) is sent.

"_method"=>"put",
 "authenticity_token"=>"fEDOZfJ6UarMD/nNM7t86zYXrEkTFtXyrXKJglYZ0Jw=",
 "user"=>{"uploads_attributes"=>{"0"=>{"id"=>"37"},
 "1"=>{"id"=>"36"},
 "2"=>{"id"=>"35"},
 "3"=>{"id"=>"34"},
 "4"=>{"id"=>"33"},
 "5"=>{"id"=>"32"},
 "6"=>{"id"=>"31"},
 "7"=>{"id"=>"30"},
 "8"=>{"id"=>"29"},
 "9"=>{"id"=>"28"},
 "10"=>{"id"=>"27"},
 "11"=>{"id"=>"26"},
 "12"=>{"id"=>"25"},
 "13"=>{"id"=>"24"},
 "14"=>{"id"=>"23"},
 "15"=>{"id"=>"22"},
 "16"=>{"id"=>"21"},
 "17"=>{"id"=>"20"},
 "18"=>{"id"=>"19"},
 "19"=>{"id"=>"18"},
 "20"=>{"id"=>"17"},
 "21"=>{"id"=>"16"},
 "22"=>{"id"=>"15"},
 "23"=>{"id"=>"14"},
 "24"=>{"id"=>"13"},
 "25"=>{"id"=>"12"},
 "26"=>{"id"=>"11"},
 "27"=>{"id"=>"10"},
 "28"=>{"upload"=>#<ActionDispatch::Http::UploadedFile:0x00000004103d18 @original_filename="robot.rres",
 @content_type="application/octet-stream",
 @headers="Content-Disposition: form-data; name=\"user[uploads_attributes][28][upload]\"; filename=\"robot.rres\"\r\nContent-Type: application/octet-stream\r\n",
 @tempfile=#<File:/tmp/RackMultipart20120505-2595-lmr2j4>>,
 "name"=>"Test",
 "file_description"=>"Test",
 "private"=>"0",
 "file_category"=>"1",
 "upload_images_attributes"=>{"0"=>{"upload_image"=>#<ActionDispatch::Http::UploadedFile:0x00000004103a98 @original_filename="Low_Res_NAO_NextGen_04.png",
 @content_type="image/png",
 @headers="Content-Disposition: form-data; name=\"user[uploads_attributes][28][upload_images_attributes][0][upload_image]\"; filename=\"Low_Res_NAO_NextGen_04.png\"\r\nContent-Type: image/png\r\n",
 @tempfile=#<File:/tmp/RackMultipart20120505-2595-16gf0jl>>,
 "preview"=>"0"}}}},
 "username"=>"chunter"},
 "commit"=>"Submit Upload",
 "id"=>"chunter"}

As you can see the parameters for both the Upload file and the Upload_Image file are sent, but only the Upload is persisted to the database.

My Update method:

  def update
    @user = User.find_by_username(params[:id])
    #Update the users uploadS
    unless @user.update_attributes(params[:user])
      session[:error] = @user.errors.full_messages

      #render :action => "show"
      respond_to do |format|
        format.html { redirect_to :back, notice: 'Update unsuccessful.' }
        format.json { head :ok }
      end
    else
      respond_to do |format|
        format.html { redirect_to :back, notice: 'Update successful.' }
        format.json { head :ok }
      end
    end    
  end

Here’s my Models (I removed extra stuff for readability):

User

class User < ActiveRecord::Base

  attr_accessible :email, :password, :password_confirmation, :remember_me, :admin, :username, :avatar, :description, :name, :country, :province, :gender, :occupation, :city, :address, :birth_date, :uploads_attributes, :avatar_attachment_size, :avatar_file_type, :banned_until, :upload_images_attributes
  has_many :posts, :dependent => :destroy, :order => 'created_at desc'
  has_many :topics, :dependent => :destroy, :order => 'created_at desc'
  has_many :viewings, :dependent => :destroy, :order => 'updated_at desc'
  has_many :uploads, :dependent => :destroy, :order => 'created_at desc'
  has_many :news, :dependent => :destroy, :order => 'created_at desc'
  has_many :events, :dependent => :destroy, :order => 'date desc'
  has_many :blog_entries, :foreign_key => :user_id
  has_many :registers
  has_many :members
  has_many :teams, :through => :members

  accepts_nested_attributes_for :uploads, :allow_destroy => true
  has_attached_file :avatar, :styles => {:thumb=> "70x70#", :small  => "150x150>" }, :default_url => "/images/missing.jpg"


end

Upload

  class Upload < ActiveRecord::Base
    include ActiveModel::Validations

    belongs_to :user
  belongs_to :upload_category, :foreign_key => :file_category  
  has_many :upload_images, :dependent => :destroy  
  accepts_nested_attributes_for :upload_images, :reject_if => lambda { |t| t[':upload_images'].nil? }
    has_attached_file :upload,  :path => ":rails_root/:class/:id/:basename.:extension", :url => ":rails_root/:class  /:id/:basename.:extension"

    attr_accessible :file_category, :file_description, :user_id, :upload, :name, :private, :uploads, :upload_images_attributes

    validates_attachment_size :upload, :less_than => 30.megabyte
    validates_presence_of :upload_file_name, :message => "must contain a valid file."
    validates :name, :presence => true
  validates :name, :length => { :maximum => 30 }

    validates_with FileValidator
end

Upload_Images

class UploadImage < ActiveRecord::Base

belongs_to :upload
has_attached_file :image, :styles => { :small => "150x150>", :large => "320x240>"}, :default_url => "/images/missing.jpg"  


end

Edit

If I take out the

 :reject_if => lambda { |t| t[':upload_images'].nil? }

in my uploads model I get an unkown attribute: upload_image error in my users controller when I attempt the update.

  • 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-03T16:09:24+00:00Added an answer on June 3, 2026 at 4:09 pm

    There were 2 problems that prevented the persistence of my Upload_Image.

    1. The following line in my upload_image model :reject_if => lambda { |t| t[‘:upload_images’].nil? } caused my persistence to fail silently because there were nil values present in the file upload I attempted to persist.
    2. I was getting the unknown attribute: upload_image because in my view I had a file_field :upload_image yet in my model I refer to the image attachment as :image. This caused the reject_if lamba to trigger in my model
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Paperclip to handle profile photo uploads in my app. They upload
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.