Arnold Ng
2006-Jun-19 16:18 UTC
[Rails] const_missing error of has_many through association
Hi, I am new to ruby on rails. I am building an association join model and encountered the following error. Does anyone know what am I missing?> NameError in StartController#home > >d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in `const_missing'': uninitialized constant MembershipI have the following tables relationships Users -------< Memberships >------- Teams I have three model classes defined as below>class Users < ActiveRecord::Base > has_many :memberships > has_many :teams, :through => :memberships >end > >class Teams < ActiveRecord::Base > has_many :memberships > has_many :users, :through => :memberships >end > >class Memberships < ActiveRecord::Base > belongs_to :team > belongs_to :user >endMy ApplicationController has the following code. My other controllers are empty.>class ApplicationController < ActionController::Base > def home > @user = Users.find(@params["id"])# Get user based on id > @memteam = @user.teams # Get all teams that this user has joined > end >endWhen I load my page, I got those errors>NameError in StartController#home >d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in `const_missing'': uninitialized constant MembershipDoes anyone know what happen? Thank you. Arnold. -- Posted via http://www.ruby-forum.com/.
Josh Susser
2006-Jun-19 16:49 UTC
[Rails] Re: const_missing error of has_many through association
Arnold Ng wrote:>>class Memberships < ActiveRecord::Base >> belongs_to :team >> belongs_to :user >>end > > When I load my page, I got those errors >>NameError in StartController#home >>d:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in `const_missing'': uninitialized constant Membership > > Does anyone know what happen?Your model class name "Memberships" is plural, while the error is that Rails can''t find the class "Membership". Rails convention is for the model class to be singular and the database table to be plural. -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/.
Possibly Parallel Threads
- Error const_missing': uninitialized constant Rails::Plugin::Err (NameError)
- `const_missing': uninitialized constant CGI::Session (NameEr
- in `const_missing': uninitialized constant CGI::Session
- const_missing: uninitialized constant Test when running unit tests
- `const_missing'': uninitialized constant Spec::Rails