Andy Stratton
2006-Nov-04 02:29 UTC
[Rails] Rails newbie - can anyone please help with many to many NoMethodError
Please can someone help with the following problem - I''m using LoginEngine and have a Users table linked many to many to a Plants table. The joining table is plants_users with plant_id and user_id (there are extra fields, so I''m avoiding has_and_belongs_to_many - plus it didn''t work :(). ::user.rb starts:- class User < ActiveRecord::Base has_many :Plants, :through => :plants_users ... ::plant.rb is:- class Plant < ActiveRecord::Base has_many :Users, :through => :plants_users end ::plant_user.rb is: class PlantUser < ActiveRecord::Base belongs_to :user belongs_to :plant end ::plant_controller.rb is class PlantController < ApplicationController before_filter :login_required scaffold :plant def list @plants = @session[''user''].plants end end So far so good (I think), but when I access this (using instantrails), I get NoMethodError in PlantController#list undefined method `plants'' for #<User:0x3969fa0>So - apparently User has no plants method - but why not - surely thats whats rails does?!I''ve tried reading loads of tutorials, changing this code umpteen times, using has_and_belongs_to_many and can''t seem to get anywhere.Please help Cheers Andy Stratton -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060926/9e3735f5/attachment.html