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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:29:51+00:00 2026-06-07T13:29:51+00:00

What I want : A site where I can upload a file and assign

  • 0

What I want:
A site where I can upload a file and assign it to an object (e.g. Person).
For the upload I am using carrierwave. I want to have two separated models: “Person” and “Attachment”. Every person has only one attachment.
In my view I would like to set the upload into a nested form, with ‘field_for’.

My Code:

#app/models/person.rb
has_one :attachment
accepts_nested_attributes_for :attachment
attr_accessible :name, :attachment_attributes

#app/models/attachment.rb
attr_accessible :description, :file
belongs_to :person
mount_uploader :file, AttachmentUploader

#app/controllers/person_controller.rb
def new
  @person = Person.new
  @person.build_attachment
end

#app/views/person/new.html.haml
= form_for @person, :html => {:multipart => true} do |f|
  = f.fields_for :attachment do |attachment_form|
    attachment_form.file_field :file
  = f.submit

My problem:
When I am trying to open new.html I am getting this error:
unknown attribute: person_id

I have no idea why this error occurs.
Somebody an idea?

(I am using rails 3.2.6 with ruby 1.8.7)

  • 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-07T13:29:52+00:00Added an answer on June 7, 2026 at 1:29 pm

    When creating the association between two models there are always two steps.

    1.) Creating the cholumns / table needed.

    When you have a 1..n or 1..1 relation there needs to be a column for association in one of the tables. This columns arent created automaticly. You need to create them. For this fiorst create a migration:

    rails g migration addColumnToTable
    

    This creates a migration file in db/migrate/ that you need to edit. In the up method add the add_colun command to add a column

    add_column :tablename, :column_name, :column_type
    

    You will find the whole documentation here: http://api.rubyonrails.org/classes/ActiveRecord/Migration.html

    Then you need to run the migration by executing rake db:migrate

    2.) Add the association to the models (This is what you have already done!)

    That should do it for you,…

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

Sidebar

Related Questions

I have a file upload site, and I want to run a maintenance script
I want to put a section in my site where people can upload things
here is a site http://www.lyrkjsw.gov.cn that can let the registered user to upload file
If i have a site where users can upload as many images as they
On my site I have a page where users can upload files to go
How can I upload a remote file from a link for example, http://site.com/file.zip to
I have an area on my site where a user can upload files to
In my site I use 10 file upload boxes. I want to get a
I want to make a section in my site where visitors can upload files
I have a WordPress site, in which type1 users can upload *.doc files 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.