ruby-on-rails – ActiveRecord :: UnknownAttributeError?

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – ActiveRecord :: UnknownAttributeError?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我只是把应用推送到一个生产Heroku环境.

基本上有一个总线模型,它有一个座位属性

class Bus < ActiveRecord::Base
  attr_accessible :seats,# other attributes
end

现在我有一个JavaScript前端,POST的JSON用于新的公交车到公车#创建动作.

当我尝试创建一个总线时,ActiveRecord会遇到一个错误

: 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 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}}

我检查了总线表实际上有座位列,它是(我在Heroku控制台中运行):

> Bus.column_names
=> ["id","name","route_id","created_at","updated_at","price","departure_time","trip_distance","trip_duration","seats"]

当然,我已经尝试迁移和加载数据库模式.我检查了attr_accessible:座位是否设置正确.

任何其他想法?

我在Heroku雪松堆栈上运行Rails 3.1.1.一切都在我的本地机器上正常工作.

解决方法

这是陈词滥调,但我早上再次尝试,它的工作完美!我怀疑这可能是某种传播问题.
原文链接:https://www.f2er.com/ruby/271687.html

猜你在找的Ruby相关文章