Heroku在Rails中为其视图设置模型上的字段时出错

时间:2012-11-28 21:16:00

标签: ruby-on-rails ruby-on-rails-3 activerecord heroku ruby-on-rails-3.2

我只是在UsersController#new

中的用户模型上设置字段
def new
  @user = User.new
  @user.next_billing_cycle = Date.today

  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @user }
  end
end

在我的开发环境中完美运行。我的用户模型有attr_accessible :next_billing_cycle,因此它也有相应的date_select字段集:

class User < ActiveRecord::Base
  attr_accessible :name, :next_billing_cycle
end

但是,在Heroku中,我收到此错误:

2012-11-28T21:02:47+00:00 app[web.1]: Started GET "/users/new" for 173.55.174.235 at 2012-11-28 21:02:47 +0000
2012-11-28T21:02:47+00:00 heroku[router]: at=info method=GET path=/users/new host=example.com fwd=173.55.174.235 dyno=web.1 queue=0 wait=0ms connect=1ms service=402ms status=500 bytes=643
2012-11-28T21:02:47+00:00 app[web.1]: 
2012-11-28T21:02:47+00:00 app[web.1]: NoMethodError (undefined method `next_billing_cycle=' for #<User:0x00000004f47618>):
2012-11-28T21:02:47+00:00 app[web.1]: 
2012-11-28T21:02:47+00:00 app[web.1]: Completed 500 Internal Server Error in 322ms
2012-11-28T21:02:47+00:00 app[web.1]: 
2012-11-28T21:02:47+00:00 app[web.1]:   app/controllers/users_controller.rb:29:in `new'
2012-11-28T21:02:47+00:00 app[web.1]: Processing by UsersController#new as HTML

更新 :我应该明确表示,已经运行heroku rake db:migrate

1 个答案:

答案 0 :(得分:0)

您的意思是使用attr_accessor吗?或next_billing_cycle是DB中的一列?