[英]Rails Model Not Updating on Capistrano deployment
Alright so I've spent considerable amount of time with this and still can't find out what's wrong. 好吧,所以我花了很多时间来解决这个问题,但仍然找不到问题所在。
Here's whats going on: I've got a model reward.rb with a method X like this: 这是怎么回事:我有一个带有方法X的模型reward.rb:
class Reward < ActiveRecord::Base
def x
puts "foo" # Method does something...
end
end
The rails app is now on a production environment, in development, if you do 如果您愿意,Rails应用程序现在可以在生产环境中进行开发
rails c
and then 接着
>> r = Reward.new
>> r.x
"foo" # I.e it works...
now, if you go into the server and do 现在,如果您进入服务器并执行
rails c
and then 接着
>> r = Reward.new
>> r.x
NoMethodError: undefined method `x' for #<Reward:0x0000000561fa08>
If you check reward.rb in the same server you'll see the method's there, actually it's the first method in the file... so, as I can see Rails is not loading the latest code of the model when it loads the console... 如果您在同一台服务器上检查reward.rb,那么您会看到该方法在那里,实际上它是文件中的第一个方法...因此,正如我所见,Rails在加载控制台时未加载模型的最新代码...
I thought it might have something to do with Rails' cache but production.rb says: 我认为这可能与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
And environment.rb: 和environment.rb:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
MyApp::Application.initialize!
And application.rb: 和application.rb:
module MyApp
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [:password]
end
end
So I've ran out of ideas... The app was deployed with capistrano, I'm using Rails 3.0.10. 因此,我的想法耗尽了……该应用程序是通过capistrano部署的,我使用的是Rails 3.0.10。
UPDATE 更新
Alright, so I figured out the problem, pretty silly to be honest, there was a models.bak folder inside app/ that someone created, on production the models were getting picked up from that folder 好吧,所以我想出了这个问题,说实话,这很愚蠢,在app /里面有人创建了一个models.bak文件夹,在生产中从那个文件夹中拾取了模型
Have you run database migrations on your deploy server? 您是否在部署服务器上运行数据库迁移?
You may need to set up a capistrano recipe to do this. 您可能需要设置一个Capistrano配方来执行此操作。 I believe an out-of-date database schema could cause this error. 我相信过时的数据库架构可能会导致此错误。
A stupid question: have you checked the reward.rb file on the server? 一个愚蠢的问题:您是否检查了服务器上的reward.rb文件? Is it the correct (new) version? 它是正确的(新)版本吗?
尝试重新启动独角兽或手动进行操作。
您必须进行rails c production
才能运行生产环境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.