Question

I've got a simple post model in my Rails 4 app that accepts_nested_attributes_for :slide. Everything is setup and running fine on my local machine in dev mode, but it throws this error on both heroku and a digital ocean server:

 app/web.1: ActiveRecord::UnknownAttributeError (unknown attribute: post_id):
 app/web.1:   app/controllers/posts_controller.rb:12:in `new' 

these are the controller lines in question, line 12 referenced above is the 3rd line below:

def new
  @post = Post.new
  @post.build_slide
end

I doubled checked and there are no pending migrations on my server or heroku and both are up-to-date with the git repo. Both the local dev and remote repos are running postgres. Everything checks out in irb as well:

2.0.0-p247 :001 > a = Post.new
=> #<Post id: nil, title: nil, en_body: nil, ko_body: nil, short_title: nil, created_at: nil,    updated_at: nil, published: nil, slug: nil, ko_title: nil>
2.0.0-p247 :002 > a.build_slide
=> #<Slide id: nil, en_title: nil, ko_title: nil, en_description: nil, ko_description: nil, active: false, created_at: nil, updated_at: nil, image_file_name: nil, image_content_type: nil, image_file_size: nil, image_updated_at: nil, link: nil, anchor: nil, post_id: nil>

Why could the servers be complaining about an unknown attribute?

Was it helpful?

Solution

Restart your heroku server it did happened with me once on heroku, I had to restart the heroku server after executing migration. Restart heroku server using

heroku restart 

from your rails app directory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top