Ruby on rails Rails 4有\u one/accepts\u嵌套的\u属性在本地工作,但不在服务器上工作
我的Rails 4应用程序中有一个简单的post模型,它接受\u嵌套的\u属性\u for:slide。在我的本地机器上,在开发模式下,一切都已设置好并运行良好,但它在heroku和digital ocean服务器上都会抛出此错误:Ruby on rails Rails 4有\u one/accepts\u嵌套的\u属性在本地工作,但不在服务器上工作,ruby-on-rails,nested-attributes,Ruby On Rails,Nested Attributes,我的Rails 4应用程序中有一个简单的post模型,它接受\u嵌套的\u属性\u for:slide。在我的本地机器上,在开发模式下,一切都已设置好并运行良好,但它在heroku和digital ocean服务器上都会抛出此错误: app/web.1: ActiveRecord::UnknownAttributeError (unknown attribute: post_id): app/web.1: app/controllers/posts_controller.rb:12:in
app/web.1: ActiveRecord::UnknownAttributeError (unknown attribute: post_id):
app/web.1: app/controllers/posts_controller.rb:12:in `new'
这些是有问题的控制器行,上面提到的第12行是下面的第3行:
def new
@post = Post.new
@post.build_slide
end
我进行了双重检查,我的服务器或heroku上没有挂起的迁移,并且都是git repo的最新版本。本地dev和远程repo都在运行postgres。irb中的所有内容都会得到验证:
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>
为什么服务器会抱怨未知属性?重新启动heroku服务器
有一次在heroku发生过,
执行迁移后,我必须重新启动heroku服务器。
使用重新启动heroku服务器
heroku restart
从rails应用程序目录。是否尝试重新启动服务器?我确实在heroku上遇到过一次,在执行迁移后,我不得不重新启动heroku服务器。从rails应用程序目录中使用“heroku Restart”重新启动heroku服务器。谢谢,修复了heroku。仍在等待我的服务器重新启动…digital ocean目前似乎有一些问题。我没有意识到digital ocean存在问题。但我相信,当它启动时,您的问题将通过重新启动服务器得到解决。我的答案解决了你的问题,你能帮我把它改成正确的吗?我还是会把:幻灯片改成:幻灯片。那迟早会出错的。你为什么这么认为?这是一个“有一个”的协会。对不起,我应该把模型贴出来,那就清楚了