I have a table with institutions and a table with projects with I
would like to join twice with a habtm-relation.
***Model institution
has_and_belongs_to_many :projects, :join_table =>
"customerinstitutions"
***Model project
has_and_belongs_to_many :institutions, :join_table =>
"customerinstitutions"
update: the error actually reads as follows:
NameError in ProjectsController#show
undefined local variable or method `institution' for #<Class:
0xb6c1b568>
RAILS_ROOT: /home/christof/Dokumente/ror/v1
Application Trace | Framework Trace | Full Trace
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
base.rb:1532:in `method_missing'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
base.rb:1750:in `compute_type'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
reflection.rb:125:in `send'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
reflection.rb:125:in `klass'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
associations/has_and_belongs_to_many_association.rb:132:in
`construct_sql'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
associations/has_and_belongs_to_many_association.rb:6:in `initialize'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
associations.rb:1032:in `new'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
associations.rb:1032:in `customerinstitutions'
app/controllers/projects_controller.rb:17:in `show'
And it looks like the source of the trouble is this line in the
CONTROLLER:
@customerinstitutions =
@project.customerinstitutions.find(:all, :order => "name")
What I don't understand: why is rails looking for a method called
"institution"?
Project has customerinstitutions and contractorinstitutions, and #show
is looking for institutions.
///ark
Project has customerinstitutions and contractorinstitutions, and #show
is looking for institutions.
But why? Didn't I specify in the model as well as in the controller,
that it should be looking for customerinstitutions?
I think the model is fine, for at least I was able to use fixtures
like this one to fill data into both the project-table and the join-
table:
***fixture for project
project_one:
name: someproject
description: blahblah
customerinstitutions: institution_one
contractorinstitutions: institution_two
However, if I remove this line from the controller/show, then the
error doesn't appear:
@customerinstitutions =
@project.customerinstitutions.find(:all, :order => "name")
Yep, I see what you mean, and I don't have a clue what's going on.
I'd start stepping through that code in the debugger.
///ark