简体   繁体   中英

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:

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 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...

I thought it might have something to do with Rails' cache but production.rb says:

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:

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
MyApp::Application.initialize!  

And 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.

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

Have you run database migrations on your deploy server?

You may need to set up a capistrano recipe to do this. 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? Is it the correct (new) version?

尝试重新启动独角兽或手动进行操作。

您必须进行rails c production才能运行生产环境。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM