12

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.

David Tuite
  • 22,258
  • 25
  • 106
  • 176

4 Answers4

10

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.

David Tuite
  • 22,258
  • 25
  • 106
  • 176
  • 32
    When this happens, try a 'heroku restart'. I just had this issue after running a migration, but restarting solve the problem. – Leonel Galán Jun 22 '12 at 21:30
  • 1
    I tried `heroku restart` and it didn't work for me so I googled this issue and came across this post and then realised that `heroku restart` defaults to my staging environment. forcing my production app by: `heroku restart --app myproductionapp` worked! – aarona May 15 '13 at 06:04
  • This must have been because you deployed the app, ran the migrations. But the app was already running, so it didn't notice the changes in db scheme. That is, you had to [restart](http://stackoverflow.com/a/15743272/52499) [it](http://stackoverflow.com/a/20188292/52499). – x-yuri Mar 25 '15 at 09:00
3

Was pulling my hair out on this one until I saw Leito's comment above.

heroku restart --app staging

fixed this one for me.

Bill Noto
  • 541
  • 4
  • 12
3

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.

Reno
  • 33,594
  • 11
  • 89
  • 102
dnszero
  • 355
  • 4
  • 11
0

Try this

attr_reader :seats
attr_accessor :seats

instead of

attr_accessible :seats
davidb
  • 8,884
  • 4
  • 36
  • 72
  • The problem seems to have fixed itself overnight. Might have been a propagation issue or something. Thanks anyway. – David Tuite Nov 16 '11 at 17:23