ActiveRecord的:: UnknownAttributeError? [英] ActiveRecord::UnknownAttributeError?
问题描述
基本上有一个 Bus
模型,它只是一个应用程序。具有座位属性
class Bus< ActiveRecord :: Base
attr_accessible:seats,#其他属性
结束
现在我有一个JavaScript前端,POST的JSON用于新总线到总线#创建
动作。
ActiveRecord不断遇到当我尝试创建总线时出错:
:POST www.busables.com/buses dyno = web.1 queue = 0 wait = 5ms service = 65ms status = 500 bytes = 728
:
:ActiveRecord :: UnknownAttributeError(未知属性:座位):
:app / controllers / buses_controller.rb:31:新'
:app / controllers / buses_controller.rb:31:在`create'
这些参数正好达到控制器的动作。我可以登录他们,并得到以下信息:
收到的总线参数:{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=>一个地方terminal_address=>另一个地方,距离=> 26362,持续时间=> 1753}}
我检查了 Bus
表中实际上有
> Bus.column_names
=> [id,name,route_id,created_at,updated_at,price,departure_time,trip_distance,trip_duration,seats]
当然,我尝试迁移并加载数据库模式。我已检查 attr_accessible:seats
是否也设置正确。
还有其他想法吗?
我在Heroku Cedar堆栈上运行Rails 3.1.1。一切正常,我的本地机器。
这是陈词滥调,但我早上再次尝试,它完美的作品!我怀疑这可能是某种传播问题。
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.
这篇关于ActiveRecord的:: UnknownAttributeError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!