[英]Rails Model Not Updating on Capistrano deployment
好吧,所以我花了很多時間來解決這個問題,但仍然找不到問題所在。
這是怎么回事:我有一個帶有方法X的模型reward.rb:
class Reward < ActiveRecord::Base
def x
puts "foo" # Method does something...
end
end
如果您願意,Rails應用程序現在可以在生產環境中進行開發
rails c
接着
>> r = Reward.new
>> r.x
"foo" # I.e it works...
現在,如果您進入服務器並執行
rails c
接着
>> r = Reward.new
>> r.x
NoMethodError: undefined method `x' for #<Reward:0x0000000561fa08>
如果您在同一台服務器上檢查reward.rb,那么您會看到該方法在那里,實際上它是文件中的第一個方法...因此,正如我所見,Rails在加載控制台時未加載模型的最新代碼...
我認為這可能與Rails的緩存有關,但是production.rb說:
MyApp::Application.configure do
config.cache_classes = false
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching = false
# SMTP settings and other stuff.. not related to caching...
end
和environment.rb:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
MyApp::Application.initialize!
和application.rb:
module MyApp
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [:password]
end
end
因此,我的想法耗盡了……該應用程序是通過capistrano部署的,我使用的是Rails 3.0.10。
更新
好吧,所以我想出了這個問題,說實話,這很愚蠢,在app /里面有人創建了一個models.bak文件夾,在生產中從那個文件夾中拾取了模型
您是否在部署服務器上運行數據庫遷移?
您可能需要設置一個Capistrano配方來執行此操作。 我相信過時的數據庫架構可能會導致此錯誤。
一個愚蠢的問題:您是否檢查了服務器上的reward.rb文件? 它是正確的(新)版本嗎?
嘗試重新啟動獨角獸或手動進行操作。
您必須進行rails c production
才能運行生產環境。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.