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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2007-Dec-24 15:29 UTC
Re: Problem with two relationships to the same table
Rakoon Smith wrote:> ActiveRecord::AssociationTypeMismatch in InscripcionController#create > Profesion expected, got String > ... > 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"}}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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---