I have a polymorphic relationship with address being able to both be owned by a member or a dependent. Everything looked great until I realized that I wouldn't know what type of object was creating it unless I'm missing something. Is there a way to tell the routing file to include the type of object?
Models:
class Member < ActiveRecord::Base
has_one :address, as: :person, dependent: :destroy
end
class Dependent < ActiveRecord::Base
has_one :address, as: :person, dependent: :destroy
end
class Address < ActiveRecord::Base
belongs_to :person, polymorphic: true
end
Controller:
def new
@person = ???
@address = Address.new(person: @person)
end
Routes Currently:
resources :members do
resources :addresses, shallow: true
resources :dependents, shallow: true do
resources :addresses, shallow: true
end
end
I have routes to address under each but would need to check for params[:member_id] or params[:dependent_id] I think. What happens when I attach notes to everything. I'm probably missing some easy way to do this in Rails, any advice would be greatly appreciated!