0

i need to create a form, which will create object which has another two objects as attributes, but those objects should be available from a dropdown list that contains templates of those objects.

class User < ActiveRecord::Base
    accepts_nested_attributes_for :adresses, :profiles
end

class Address < ActiveRecord::Base
    attr_accessible :city, :country
    belongs_to :user
end

class Profile < ActiveRecord::Base
    attr_accessible :nickname, :password
    belongs_to :user
end

tricky part might be, that User has no column 'address_id' or 'profiles_id', everything should go to the Profile and Address, which are being created in the same moment as the User (they have the same attributes as their templates) I could really use some help, dont expext full code solution, but some hints would be nice

1 Answer 1

2

Try this setup:

class User < ActiveRecord::Base
  has_one :address
  has_one :profile

  accepts_nested_attributes_for :address, :profile
  attr_accessible :adress_attributes, :profile_attributes
end

class Address < ActiveRecord::Base
  attr_accessible :city, :country
  belongs_to :user
end

class Profile < ActiveRecord::Base
  attr_accessible :nickname, :password
  belongs_to :user
end

See doc

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.