I just pushed an app to a production Heroku environment.
Basically there is a Bus
model and it has a seats
attribute
class Bus < ActiveRecord::Base
attr_accessible :seats, # other attributes
end
Now I have a JavaScript frontend which POST's JSON for new buses to the buses#create
action.
ActiveRecord keeps encountering an error when I try to create a bus:
: POST www.busables.com/buses dyno=web.1 queue=0 wait=5ms service=65ms status=500 bytes=728
:
: ActiveRecord::UnknownAttributeError (unknown attribute: seats):
: app/controllers/buses_controller.rb:31:in `new'
: app/controllers/buses_controller.rb:31:in `create'
The parameters are reaching the controller action fine. I can log them and I get the folowing:
The bus parameters received: {"seats"=>"24", "departure_time(1i)"=>"2011", "departure_time(2i)"=>"11", "departure_time(3i)"=>"25", "departure_time(4i)"=>"16", "departure_time(5i)"=>"15", "route_attributes"=>{"summary"=>"N51", "beginning_address"=>"A place", "terminal_address"=>"Another place", "distance"=>26362, "duration"=>1753}}
I checked that the Bus
table actually has the seats
column and it does (I ran this in the Heroku console):
> Bus.column_names
=> ["id", "name", "route_id", "created_at", "updated_at", "price", "departure_time", "trip_distance", "trip_duration", "seats"]
And of course I've tried migrating and loading the database schema. I've checked that the attr_accessible :seats
is set correctly also.
Any other ideas?
I'm running Rails 3.1.1 on the Heroku Cedar stack. Everything works fine on my local machine.
It's cliché but I tried again in the morning and it works perfectly! I suspect it might have been a propagation issue of some sort.
I had this same issue with my Heroku app in production, but not with my nearly identical app in staging.
What was the difference? My staging app only had 1 web dyno instead of 2.
So I manually scaled my Production app down to 0 web dynos, then back up to 2.
BAM! Problem solved.
Was pulling my hair out on this one until I saw Leito's comment above.
heroku restart --app staging
fixed this one for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With