0

我很簡單地在UsersController#new設置我的用戶模型的字段錯誤:給出的Heroku在Rails的模型上設置一個字段其觀點

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 "https://stackoverflow.com/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 

UPDATE:我應該明確表示,我確實運行heroku rake db:migrate

+1

您是否在遠程數據庫上運行所有遷移? – jdoe

+0

如果您在Heroku啓動應用程序後運行遷移,則可能需要'heroku restart',因爲Rails在生產中默認緩存數據庫模式。 – willglynn

+0

@willglynn - 我沒有做'heroku重啓'。目前我不能,但會在不久的將來嘗試。 –

回答

0

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

+1

如果它在開發環境中工作,但不在Heroku上,也許你有一個遷移問題。你確定列上存在Heroku嗎? – CambridgeMike

+0

他使用'attr_accessible',而不是'attr_accessor'。 – willglynn

+0

@willglynn right。如果它是attr_accessor那麼next_billing_cycle =會被定義。attr_accessible只是一個白名單,因爲我相信你知道。 – CambridgeMike

相關問題