Ruby on Rails through Heroku object associations :belongs_to :has_many -
real newb question here: i've got courses
class course < activerecord::base attr_accessible :name, :number has_many :posts validates :name, presence: true validates :number, presence: true validates :number, :format => { :with => /\a\d\d[-]?\d\d\d\z/} end
and i've got posts
class post < activerecord::base attr_accessible :comments, :course_id, :difficulty, :enjoyability, :hours, :professor, :ranking, :semester, :usefulness belongs_to :course end
almost have auto-generated rails. there couple of things try can't work:
when "show" course, want show each post associated course. however, i've tried has given me error.
after entering 1 post database (heroku forced me use postgresql) index form no longer renders.
i'm positive i'm missing associations between them. have ideas i'm doing wrong?
you may posts through course instance:
@course = course.find(params[:id]) @posts = @course.posts
Comments
Post a Comment