Rails 3 用に作成されたチュートリアルに従っています。Rails 3.2 を使用していますが、正しく従っていると思いますが、エラーが発生しています。私のクラスは次のとおりで、task.admin_users_tasks を使用するとエラーが発生します。
class Task < ActiveRecord::Base
attr_accessible :name, :project_id, :task_id, :permalink, :visible, :position, :created_at
belongs_to :project
has_and_belongs_to_many :admin_users
has_many :admin_users_tasks
end
class AdminUsersTask < ActiveRecord::Base
attr_accessible :admin_user_id, :task_id, :created_at, :updated_at
belongs_to :admin_user, :class_name => "AdminUser" :foreign_key => 'admin_user_id'
belongs_to :task
end
class AdminUser < ActiveRecord::Base
attr_accessible :first_name, :last_name, :username, :email
has_and_belongs_to_many :projects
has_and_belongs_to_many :tasks
has_many :admin_users_tasks
has_many :admin_users_projects
end
Rails コンソール
1.9.3-p362 :032 > task
=> #<Task id: 1, project_id: 6, permalink: "taskytask", position: 1, visible: true, created_at: "2013-02-21 05:08:01", updated_at: "2013-02-21 05:08:01", name: "Task Name for Noname Project">
1.9.3-p362 :033 > me
=> #<AdminUser id: 1, first_name: "Larry", last_name: "David", email: "larry.david@mail.com", hashed_password: "c9f4e8d3aaa265033c2f517abd5d347bd81d67fa", created_at: "2013-02-21 04:43:20", updated_at: "2013-02-21 04:43:20", username: "larrydavid", salt: "d4189f8db685776d3a3c3c4d0700786b7879362d">
1.9.3-p362 :034 > me.admin_users_tasks
=> []
1.9.3-p362 :035 > task.admin_users_tasks
NoMethodError: undefined method `admin_users_tasks' for #<Task:0x007fca9e159f58>
from /Users/larrydavid/.rvm/gems/ruby-1.9.3-p362/gems/activemodel- 3.2.11/lib/active_model/attribute_methods.rb:407:in `method_missing'
from /Users/larrydavid/.rvm/gems/ruby-1.9.3-p362/gems/activerecord- 3.2.11/lib/active_record/attribute_methods.rb:149:in `method_missing'
from (irb):35
from /Users/larrydavid/.rvm/gems/ruby-1.9.3-p362/gems/railties- 3.2.11/lib/rails/commands/console.rb:47:in `start'
from /Users/larrydavid/.rvm/gems/ruby-1.9.3-p362/gems/railties- 3.2.11/lib/rails/commands/console.rb:8:in `start'
from /Users/larrydavid/.rvm/gems/ruby-1.9.3-p362/gems/railties- 3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
1.9.3-p362 :036 >