I have the following tables: Users, Default Prices, Clients, Client Prices. What I’d like is to have the default_prices automatically fill in the client_prices table when a new client is created. It looks like I might be able to use a similar solution to this answer. What I would like to happen is when a new client is created by a user, all of the client_prices for the client are populated by the default_prices table.
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :stripe_token, :default_prices_attributes
has_many :default_prices
has_many :clients
accepts_nested_attributes_for :default_prices, :allow_destroy => true
class DefaultPrice < ActiveRecord::Base
attr_accessible :price, :user_id, :visit_type, :id
belongs_to :user
end
class Client < ActiveRecord::Base
attr_accessible :active, :address_1, :address_2, :city, :email, :first_name, :last_name, :state, :user_id, :zip, :client_prices_attributes
belongs_to :user
has_many :client_prices
accepts_nested_attributes_for :client_prices_attributes
class ClientPrice < ActiveRecord::Base
attr_accessible :price, :client_id, :visit_type, :id
belongs_to :uclient
end
You can add before_create block to copy default price.