Reputation: 4634
My app run perfectly locally, but it encountered some trouble on Heroku
.
heroku logs
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]:
I want to create a post
and gave the author_id
= current_author.id
.
#in post controller
def create
@post = Post.new(post_params)
@post.author_id = current_author.id if current_author
...
I've put this project on Github
Upvotes: 0
Views: 58
Reputation: 1260
As others pointed the possible solution. to make sure though,
run heroku run rake db:version
and see if it matches your latest migration version in db/migrate/*
If it doesnt run heroku run rake db:migrate
as oreoluwa and lolosco have said already.
Upvotes: 1
Reputation: 5623
I think you recently added the author reference to the posts table. To fix the error, I'd say you should try to do heroku run rake db:migrate
. Let me know if that helps
Upvotes: 1