Друзья У меня есть следующие модели
class Project < ActiveRecord::Base
has_many :milestones_projects
has_many :milestones, :through => :milestones_projects
validates :projectname, :presence=>true, :length=> {:maximum=>250}, :uniqueness=>true
validates :location,:presence=>true
end
class Milestone < ActiveRecord::Base
has_many :milestones_projects
has_many :projects, :through => :milestones_projects
validates :name, :presence => true, :length => {:maximum => 250}
validates :days, :presence => true, :length => {:maximum => 3}
validates :stage, :presence => true
end
class MilestonesProjects < ActiveRecord::Base
belongs_to :milestones,:foreign_key => 'milestone_id'
belongs_to :projects,:foreign_key => 'project_id'
end
Так что у меня есть отношение многие ко многим между проектом и этапом.
в irb, я хочу получить объект коллекции, поэтому яЯ использую следующее:
irb(main):001:0> me=Project.find(1)
=> #<Project id: 1, location_id: 1, projectname: "Sample 2", description: "Sample 2", i
spublished: true, created_at: "2011-09-02 08:26:41", updated_at: "2011-09-07 10:26:48">
здесь 'me' - это массив, содержащий сведения о первом проекте, и теперь я пытаюсь получить сведения о вехах, связанных с этим проектом. Для этого я пытаюсь сделать следующее
irb(main):002:0> me.milestones
, но это дает мне ошибку вроде
NameError: неинициализированная константа Project :: MilestonesProject от c: /RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9 / lib / active_record / base.rb: 1205: в compute_type'
from c:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/
active_record/reflection.rb:162:in
отправить 'с c: /RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/ active_record /refle.rb: 162: в klass'
from c:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/
active_record/reflection.rb:346:in
source_reflection 'из c: /RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/ active_record / refle.rb: 346: в collect'
from c:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/
active_record/reflection.rb:346:in
source_reflection 'от c: /RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/ active_record / reflection.rb: 377: в check_validity!'
from c:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/
active_record/associations/association_proxy.rb:61:in
инициализировать 'из c: /RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/ active_record / association / association_collection.rb: 23:в initialize'
from c:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/
active_record/associations/has_many_association.rb:11:in
инициализировать 'из c: /RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/ active_record / association.rb: 1483: в new'
from c:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/
active_record/associations.rb:1483:in
вехах' из (irb): 2 из: 0
поэтому друзья, пожалуйста, помогите мне ..
мне нужно выполнить некоторые команды, такие как
milestone_count=project.milestones.size