我的应用在本地运行完美,但在Heroku
上遇到了一些问题。
heroku日志
2016-07-05T16:29:58.946783+00:00 app[web.1]: Started GET "/posts/new" for 110.30.34.50 at 2016-07-05 16:29:58 +0000
2016-07-05T16:29:58.955329+00:00 app[web.1]: Rendered posts/_form.html.erb (2.4ms)
2016-07-05T16:29:58.955545+00:00 app[web.1]: Rendered posts/new.html.erb within layouts/application (3.4ms)
2016-07-05T16:30:05.508001+00:00 app[web.1]: Started POST "/posts" for 110.30.34.50 at 2016-07-05 16:30:05 +0000
2016-07-05T16:30:05.510085+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"0DzbuSXUyjZ4FRYietP3QSdmjfHymWyu7INcGpm79b2PgR+3LD99TS6gkYCF0FCLLHso9U7YqMh1tzr48ch8Jw==", "post"=>{"title"=>"123", "content"=>"123"}, "commit"=>"Create Post"}
2016-07-05T16:30:05.515017+00:00 app[web.1]: app/controllers/posts_controller.rb:32:in `create'
2016-07-05T16:30:05.512757+00:00 app[web.1]: Author Load (1.2ms) SELECT "authors".* FROM "authors" WHERE "authors"."id" = $1 ORDER BY "authors"."id" ASC LIMIT 1 [["id", 1]]
2016-07-05T16:30:05.513954+00:00 app[web.1]: Completed 500 Internal Server Error in 4ms (ActiveRecord: 1.2ms)
2016-07-05T16:30:05.515003+00:00 app[web.1]:
2016-07-05T16:30:05.515016+00:00 app[web.1]: NoMethodError (undefined method `author_id=' for #<Post:0x007fcf1cc579f0>):
2016-07-05T16:30:05.509973+00:00 app[web.1]: Processing by PostsController#create as HTML
2016-07-05T16:30:05.515018+00:00 app[web.1]:
2016-07-05T16:30:05.515019+00:00 app[web.1]:
我想创建post
并给出author_id
= current_author.id
。
#in post controller
def create
@post = Post.new(post_params)
@post.author_id = current_author.id if current_author
...
我已将此项目放在Github
上答案 0 :(得分:1)
我认为您最近添加了作者对posts表的引用。为了解决这个错误,我说你应该尝试heroku run rake db:migrate
。如果有帮助,请告诉我
答案 1 :(得分:1)
在heroku上迁移db
heroku run rake db:migrate
答案 2 :(得分:1)
正如其他人指出可能的解决方案。但要确保,
运行heroku run rake db:version
,看看它是否与db/migrate/*
如果没有运行heroku run rake db:migrate
as oreoluwa和lolosco已经说过了。