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:

  1. when "show" course, want show each post associated course. however, i've tried has given me error.

  2. 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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -