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
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.
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
migrate db on heroku
heroku run rake db:migrate
Related
I have a voting platform that I'm building for my company and I am very close to finishing it but the actual voting is failing while in production. I've done all my migrating and everything, and it's still working in development.
Here are the logs I'm receiving from heroku:
2019-01-11T18:33:59.235681+00:00 app[web.1]: I,
[2019-01-11T18:33:59.235579 #4] INFO -- :
[772bc37c-00ee-43da-aa81-564d353553bb] Started POST
"/ballots/13/votes" for 75.150.214.2 at 2019-01-11 18:33:59 +0000
2019-01-11T18:33:59.236373+00:00 app[web.1]: I,
[2019-01-11T18:33:59.236296 #4] INFO -- :
[772bc37c-00ee-43da-aa81-564d353553bb] Processing by
VotesController#create as HTML 2019-01-11T18:33:59.236437+00:00
app[web.1]: I, [2019-01-11T18:33:59.236378 #4] INFO -- :
[772bc37c-00ee-43da-aa81-564d353553bb] Parameters: {"utf8"=>"✓",
"authenticity_token"=>"Y/vAh2kYPskozS2yQn3Ky1fOq41abLUjlxho0Q+zXHSndVlaSfwYz7bdoqvintdBXrYNDhsbIduYICpUAx3/0g==",
"user_vote"=>"Why", "vote"=>{"comment"=>""}, "commit"=>"Cast Vote",
"ballot_id"=>"13"} 2019-01-11T18:33:59.239540+00:00 app[web.1]: D,
[2019-01-11T18:33:59.239464 #4] DEBUG -- :
[772bc37c-00ee-43da-aa81-564d353553bb] Ballot Load (0.7ms) SELECT
"ballots".* FROM "ballots" WHERE "ballots"."id" = $1 LIMIT $2 [["id",
13], ["LIMIT", 1]] 2019-01-11T18:33:59.240333+00:00 app[web.1]: I,
[2019-01-11T18:33:59.240244 #4] INFO -- :
[772bc37c-00ee-43da-aa81-564d353553bb] Completed 500 Internal Server
Error in 4ms (ActiveRecord: 0.7ms) 2019-01-11T18:33:59.240846+00:00
app[web.1]: F, [2019-01-11T18:33:59.240770 #4] FATAL -- :
[772bc37c-00ee-43da-aa81-564d353553bb]
2019-01-11T18:33:59.240917+00:00 app[web.1]: F,
[2019-01-11T18:33:59.240847 #4] FATAL -- :
[772bc37c-00ee-43da-aa81-564d353553bb]
ActiveModel::UnknownAttributeError (unknown attribute 'comment' for
Vote.):' '2019-01-11T18:33:59.240981+00:00 app[web.1]: F,
[2019-01-11T18:33:59.240914 #4] FATAL -- :
[772bc37c-00ee-43da-aa81-564d353553bb]
2019-01-11T18:33:59.241051+00:00 app[web.1]: F,
[2019-01-11T18:33:59.240987 #4] FATAL -- :
[772bc37c-00ee-43da-aa81-564d353553bb]
app/controllers/votes_controller.rb:10:in `create'
2019-01-11T18:34:07.533587+00:00 heroku[run.2070]: State changed from
up to complete bobby#bobby-Al
Here's my code for vote create
def create
#ballot = Ballot.find(params[:ballot_id])
#vote = #ballot.votes.new(user_vote: params[:user_vote], comment: params[:vote][:comment])
#vote.user_id = current_user.id
if !current_user.votes.find_by(ballot_id: params[:ballot_id])
#vote.save
redirect_to ballot_path(params[:ballot_id])
else
flash[:alert] = "You've already voted on this ballot"
redirect_to ballot_path(params[:ballot_id])
end
end
It seems like a migration problem, just make sure to run your migrations for the environment production on heroku like this:
heroku run rake db:migrate
Restart your app
heroku restart --app my_app_name
Important
If you generate a migration that creates a table and make a push to heroku, to add another column to that table you shouldn't modify that one, instead you should create another one for that.
When you run rake db:migrate, rails register that on the table schema_migrations, so if you modify a migrate that is already registered is not going to be executed again. This could be the case, check directly on your database and see if the column is there.
The application runs perfectly in development(local server) but not in production.
I have the following in heroku logs(I have edited the logs to be easier to read, I just included what I think are the errors):
2015-05-15T23:58:43.894626+00:00 app[web.1]: Rendered layouts/_header.html.erb (8.5ms)
2015-05-15T23:58:43.885011+00:00 app[web.1]: Rendered movies/index.html.erb within layouts/application (17.5ms)
2015-05-15T23:58:43.896788+00:00 app[web.1]: ActionView::Template::Error (undefined method `scard' for nil:NilClass):
2015-05-15T23:58:43.896785+00:00 app[web.1]:
2015-05-15T23:58:43.896790+00:00 app[web.1]: 19: <%if signed_in?%>
2015-05-15T23:58:43.896791+00:00 app[web.1]: 20: <li>
2015-05-15T23:58:43.896794+00:00 app[web.1]: 22: <i class="fi-shopping-cart"></i> My Cart (<span class="cart-count"><%=current_user.cart_count%></span>)
2015-05-15T23:58:43.896793+00:00 app[web.1]: 21: <%= link_to cart_path do%>
2015-05-15T23:58:43.896796+00:00 app[web.1]: 23: <%end%>
2015-05-15T23:58:43.896797+00:00 app[web.1]: 24: </li>
2015-05-15T23:58:43.896799+00:00 app[web.1]: 25: <li><%=link_to current_user.email, edit_user_registration_path%></li>
2015-05-15T23:58:43.896801+00:00 app[web.1]: app/models/user.rb:36:in `cart_count'
2015-05-15T23:58:33.939033+00:00 app[web.1]: Completed 500 Internal Server Error in 3ms
2015-05-15T23:58:33.933343+00:00 app[web.1]: Started GET "/movies/2" for 160.9.1.112 at 2015-05-15 23:58:33 +0000
2015-05-15T23:58:33.935944+00:00 app[web.1]: Processing by MoviesController#show as HTML
2015-05-15T23:58:33.935966+00:00 app[web.1]: Parameters: {"id"=>"2"}
2015-05-15T23:58:33.938157+00:00 app[web.1]: Movie Load (1.3ms) SELECT "movies".* FROM "movies" WHERE "movies"."id" = $1 LIMIT 1 [["id", 2]]
2015-05-15T23:58:33.939854+00:00 app[web.1]:
2015-05-15T23:58:33.939856+00:00 app[web.1]: NoMethodError (undefined method `sismember' for nil:NilClass):
2015-05-15T23:58:33.939858+00:00 app[web.1]: app/models/movie.rb:20:in `cart_action'
2015-05-15T23:58:33.939859+00:00 app[web.1]: app/controllers/movies_controller.rb:9:in `show'
2015-05-15T23:58:28.575297+00:00 app[web.1]: Started GET "/movies/1" for 160.9.1.112 at 2015-05-15 23:58:28 +0000
2015-05-15T23:58:28.581745+00:00 app[web.1]: Parameters: {"id"=>"1"}
2015-05-15T23:58:28.635038+00:00 app[web.1]: Completed 500 Internal Server Error in 53ms
2015-05-15T23:58:28.581412+00:00 app[web.1]: Processing by MoviesController#show as HTML
2015-05-15T23:58:28.618562+00:00 app[web.1]: Movie Load (1.6ms) SELECT "movies".* FROM "movies" WHERE "movies"."id" = $1 LIMIT 1 [["id", 1]]
2015-05-15T23:58:28.636023+00:00 app[web.1]:
2015-05-15T23:58:28.636027+00:00 app[web.1]: NoMethodError (undefined method `sismember' for nil:NilClass):
2015-05-15T23:58:28.636029+00:00 app[web.1]: app/models/movie.rb:20:in `cart_action'
2015-05-15T23:58:28.636031+00:00 app[web.1]: app/controllers/movies_controller.rb:9:in `show'
movie.rb:
class Movie < ActiveRecord::Base
has_many :purchases
has_many :buyers, through: :purchases
before_save :embed_video_url
def poster
"http://ia.media-imdb.com/images/M/#{poster_url}"
end
def imdb
"http://www.imdb.com/title/#{imdb_id}/"
end
def embed_video_url
self.video_url = "//www.youtube.com/embed/#{video_url.split('v=')[1].split('&list')[0]}"
end
def cart_action(current_user_id)
if $redis.sismember "cart#{current_user_id}", id
"Remove from"
else
"Add to"
end
end
end
I followed the official guide from heroku "https://devcenter.heroku.com/articles/redistogo"
Even the test run ok but cant run in production
I know it's exhausting to check all these line so I will appreciate any help
PS: In development/local server run perfect
The error is appearing in the logs. See carefully.
NoMethod Error (undefined method sismember' for nil:NilClass): 2015-05 15T20:59:10.873219+00:00 app[web.1]: app/models/movie.rb:20:incart_action'
I have a rails app using Devise with confirmable emails. The emails are sending fine, and the confirmation link is working perfectly in development. But in production on Heroku, it doesn't work at all.
Again, the emails send fine on production, the token is generated, but when clicked, the page just redirects to the 'resend confirmation instructions' page. Is there something missing for production to make this work? Any suggestions or help?
Here's my logs from development:
Started GET "/users/confirmation?confirmation_token=SusKNC1PyZ4ayJxL9asR" for 127.0.0.1 at 2014-07-13 21:32:02 -0400
Processing by Devise::ConfirmationsController#show as HTML
Parameters: {"confirmation_token"=>"SusKNC1PyZ4ayJxL9asR"}
User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = '28535b0ce6b4cb809463749ccad8ae0c8e92f6e7ce6ea2b9262dc6be87eb1fff' ORDER BY "users"."id" ASC LIMIT 1
(0.1ms) BEGIN
SQL (0.9ms) UPDATE "users" SET "confirmation_token" = $1, "confirmed_at" = $2, "updated_at" = $3 WHERE "users"."id" = 3 [["confirmation_token", nil], ["confirmed_at", "2014-07-14 01:32:02.960080"], ["updated_at", "2014-07-14 01:32:02.960674"]]
(0.5ms) COMMIT
Redirected to http://localhost:3000/users/sign_in
and here is my logs from Heroku
2014-07-14T01:36:05.606623+00:00 heroku[router]: at=info method=GET path="/users/confirmation" host=www.———.— request_id=76de591e-0948-4b89-93b1-eeb9431b2b9c fwd="72.229.255.68" dyno=web.1 connect=2 service=18 status=304 bytes=1218
2014-07-14T01:36:05.585691+00:00 app[web.1]: Started GET "/users/confirmation" for 72.229.255.68 at 2014-07-14 01:36:05 +0000
2014-07-14T01:36:05.594512+00:00 app[web.1]: Rendered devise/shared/_links.html.haml (0.5ms)
2014-07-14T01:36:05.594570+00:00 app[web.1]: Rendered devise/confirmations/new.html.haml within layouts/application (3.1ms)
2014-07-14T01:36:05.596841+00:00 app[web.1]: Rendered layouts/_header.html.haml (1.1ms)
2014-07-14T01:36:05.588617+00:00 app[web.1]: Processing by Devise::ConfirmationsController#show as HTML
2014-07-14T01:36:05.597479+00:00 app[web.1]: Completed 200 OK in 9ms (Views: 6.3ms | ActiveRecord: 0.0ms)
I had the same kind of error: "Confirmation cannot be blank" on production, even though it works on my local machine. For me the problem was the free account of WWWhisper does not permit unauthorized access and treats the email confirmation link as unauthorized.
I'm so dumb, just fixed this after I submitted. The problem was with my url. I entered the root domain in my production.rb file for the smtp settings. But I actually have a www url that the root domain redirects too. Ugh
I have a rails 4 app deployed on heroku which displays the following error:
2014-06-30T21:41:49.904494+00:00 app[web.1]: CACHE (0.0ms) SELECT COUNT(*) FROM "profiles"
2014-06-30T21:41:49.909372+00:00 app[web.1]: CACHE (0.0ms) SELECT COUNT(*) FROM "profiles"
2014-06-30T21:41:49.909380+00:00 app[web.1]: CACHE (0.0ms) SELECT COUNT(*) FROM "profiles"
2014-06-30T21:41:49.914865+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.0.0/gems/rails_admin-0.6.2/app/views/rails_admin/main/_form_filtering_multiselect.html.haml (11.8ms)
2014-06-30T21:41:49.914875+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.0.0/gems/rails_admin-0.6.2/app/views/rails_admin/main/_form_filtering_multiselect.html.haml (11.8ms)
2014-06-30T21:41:49.677490+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.0.0/gems/rails_admin-0.6.2/app/views/rails_admin/main/_form_field.html.haml (4.4ms)
2014-06-30T21:41:49.888037+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.0.0/gems/rails_admin-0.6.2/app/views/rails_admin/main/_form_field.html.haml (2.7ms)
2014-06-30T21:41:50.330339+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.0.0/gems/rails_admin-0.6.2/app/views/rails_admin/main/_form_field.html.haml (6.1ms)
2014-06-30T21:41:50.330358+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.0.0/gems/rails_admin-0.6.2/app/views/rails_admin/main/_form_field.html.haml (6.1ms)
This happens with every asset file rails_admin needs leading to an infinite loop and:
2014-06-30T21:41:38.404015+00:00 heroku[web.1]: Process running mem=2540M(496.1%)
2014-06-30T21:41:38.404374+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
I've tried using multiple dynos and applying somo configurations in application.rb
# config/application.rb
config.assets.precompile += ['rails_admin/rails_admin.css', 'rails_admin/rails_admin.js']
config.assets.initialize_on_precompile = false
I recently connected a remote DB to the production version of my site. However, now my routes do not work.
In my Heroku logs, my app is looking for Parameters: {"id"=>"edit"}.
But there is not an :id parameter in my database. The only index specified is order_id.
How can I edit routes.db so that the order_id is used in my paths? And is this even necessary or is there something else I should look at?
List of columns in local db:
1.9.3-p392 :001 > Order.column_names
=> ["order_id", "product_status", "img_reference", "img_source", "user_email", "user_name", "user_address", "user_city", "user_zipcode", "user_state", "product_size", "product_type", "payment_id", "image_file_name", "image_content_type", "image_file_size", "image_updated_at"]
List of columns in remote db:
irb(main):001:0> Order.column_names
=> ["order_id", "order_date", "product_status", "img_reference", "img_source", "user_email", "user_name", "user_address", "user_city", "user_zipcode", "user_state", "product_size", "product_type", "uservendor_id", "paypal_confirmation"]
Again, my routes seem to work just fine in my development version.
The only difference I can think of is there's a few extra columns in my remote db which I don't think should effect the routes.
This is the error I get in my Heroku logs:
2014-05-08T15:28:55.461192+00:00 app[web.1]: Started GET "/orders//edit" for 76.102.227.168 at 2014-05-08 15:28:55 +0000
2014-05-08T15:28:55.465958+00:00 app[web.1]: Processing by OrdersController#show as HTML
2014-05-08T15:28:55.461180+00:00 app[web.1]: Started GET "/orders//edit" for 76.102.227.168 at 2014-05-08 15:28:55 +0000
2014-05-08T15:28:55.465965+00:00 app[web.1]: Processing by OrdersController#show as HTML
2014-05-08T15:28:55.465988+00:00 app[web.1]: Parameters: {"id"=>"edit"}
2014-05-08T15:28:55.466009+00:00 app[web.1]: Parameters: {"id"=>"edit"}
2014-05-08T15:28:55.469914+00:00 app[web.1]: Completed 404 Not Found in 4ms
2014-05-08T15:28:55.469922+00:00 app[web.1]: Completed 404 Not Found in 4ms
2014-05-08T15:28:55.470930+00:00 app[web.1]:
2014-05-08T15:28:55.470933+00:00 app[web.1]: ActiveRecord::RecordNotFound (Couldn't find Order without an ID):
2014-05-08T15:28:55.470935+00:00 app[web.1]: app/controllers/orders_controller.rb:69:in `set_order'
2014-05-08T15:28:55.470938+00:00 app[web.1]:
2014-05-08T15:28:55.470937+00:00 app[web.1]:
2014-05-08T15:28:55.470943+00:00 app[web.1]:
2014-05-08T15:28:55.470945+00:00 app[web.1]: ActiveRecord::RecordNotFound (Couldn't find Order without an ID):
2014-05-08T15:28:55.470946+00:00 app[web.1]: app/controllers/orders_controller.rb:69:in `set_order'
2014-05-08T15:28:55.470948+00:00 app[web.1]:
2014-05-08T15:28:55.470949+00:00 app[web.1]:
So, in ActiveRecord if you have a custom primary key you need to specify it in the model
class Order
self.primary_key = :order_id
Docs: http://guides.rubyonrails.org/active_record_basics.html#overriding-the-naming-conventions