jackdempsey / acts_as_commentable

The ActiveRecord acts_as_commentable plugin
http://juixe.com/svn/acts_as_commentable/
MIT License
834 stars 178 forks source link

unknown attribute: post_id #65

Closed edorgeville closed 8 years ago

edorgeville commented 8 years ago

When trying to fetch comments I get the following error :

ActiveRecord::UnknownAttributeError in PostsController#create_comment
unknown attribute: post_id
Extracted source (around line #22):
    comment = @post.comments.create <<--- Where it crashes
    comment.author_name = params[:name]
    comment.author_email = params[:email]
    comment.comment = params[:comment]

This happens right after using the rails g comments command and adding acts_as_commentable to Post. Any idea ?

edorgeville commented 8 years ago

Also

irb(main):009:0> Post.first.comments
  Post Load (0.6ms)  SELECT  "posts".* FROM "posts"   ORDER BY date ASC LIMIT 1
  Comment Load (0.3ms)  SELECT "comments".* FROM "comments"  WHERE "comments"."post_id" = ?  ORDER BY created_at ASC  [[nil, 5056]]
SQLite3::SQLException: no such column: comments.post_id: SELECT "comments".* FROM "comments"  WHERE "comments"."post_id" = ?  ORDER BY created_at ASC
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: comments.post_id: SELECT "comments".* FROM "comments"  WHERE "comments"."post_id" = ?  ORDER BY created_at ASC
edorgeville commented 8 years ago

Found it ! That was all my fault :sweat_smile:
In models/post.rb, I had forgotten to remove a line from our old comment integration :

class Post < ActiveRecord::Base
    include ContentModule

    acts_as_commentable

    # has_many :comments # <----- wasn't commented
    has_and_belongs_to_many :authors
    has_and_belongs_to_many :categories
    has_and_belongs_to_many :tags

:sob: