Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. class Lesson < ActiveRecord::Base
  2. has_many :lessons_units, :foreign_key => "lesson_id",
  3. :dependent => :destroy
  4. has_many :units, :through => :lessons_units
  5. end
  6.  
  7. class Unit < ActiveRecord::Base
  8. has_many :lessons_units, :foreign_key => "unit_id",
  9. :dependent => :destroy
  10. has_many :lessons, :through => :lessons_units
  11. end
  12.  
  13.  
  14. class LessonsUnits < ActiveRecord::Base
  15. attr_accessible :lesson_id, :unit_id
  16.  
  17. belongs_to :unit
  18. belongs_to :lesson
  19.  
  20. validates :unit_id, :presence => true
  21. validates :lesson_id, :presence => true
  22. end
  23.  
  24. 1.9.3p194 :001 > Unit.lessons.build
  25. NoMethodError: undefined method `lessons' for #<Class:0x007fe733c29f30>
  26. from /Users/robert/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/dynamic_matchers.rb:50:in `method_missing'
  27.  
  28. def create
  29. @unit = Unit.find(params[:unit_id])
  30. @lesson = @unit.lessons.build(params[:lesson])
  31.  
  32. uninitialized constant Unit::LessonsUnit
  33.  
  34. LessonsUnits -
  35.  
  36. class LessonsUnits < ActiveRecord::Base
  37.  
  38. class LessonsUnit < ActiveRecord::Base
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement