Problem with two relationships to the same table

Hi all,

When I try to save a form with two collection_select I get this error:

ActiveRecord::AssociationTypeMismatch in InscripcionController#create
Profesion expected, got String

I think that the relationship between elements is well defined, but in
this case I have two relationships leading to the same table (one for
the father and one for the mother):

class Profesion < ActiveRecord::Base
has_many :titulars_padre, :class_name=> “Titular”, :foreign_key =>
“profesion_padre_id”
has_many :titulars_madre, :class_name=> “Titular”, :foreign_key =>
“profesion_madre_id”
end

class Titular < ActiveRecord::Base
has_many :alumnos
belongs_to :profesion_padre, :class_name=> “Profesion”, :foreign_key
=> “profesion_padre_id”
belongs_to :profesion_madre, :class_name=> “Profesion”, :foreign_key
=> “profesion_madre_id”
end

I get the error when the execution reach this point:
t=Titular.new(params[:titular])

The params of the request are:

Request
Parameters: {“commit”=>“Create”, “titular”=>{“profesion_padre”=>“10”,
“profesion_madre”=>“4”}}

Thanks in advance

Rakoon Smith wrote:

 t=Titular.new(params[:titular])

The params of the request are:

Request
Parameters: {“commit”=>“Create”, “titular”=>{“profesion_padre”=>“10”,
“profesion_madre”=>“4”}}

The select helpers in your view should be

<%= select :titular, :profesion_padre_id %> and
<%= select :titular, :profesion_madre_id %>, not
<%= select :titular, :profesion_padre %> and
<%= select :titular, :profesion_madre %>.


We develop, watch us RoR, in numbers too big to ignore.