gpt4 book ai didi

ruby-on-rails - 尽管初始化程序中需要模型,但 Rails 3 中未定义的类/模块 X

转载 作者:行者123 更新时间:2023-12-03 21:07:07 24 4
gpt4 key购买 nike

我们使用 Rails.cache 并在加载调用类 X 的页面时看到未定义的类/模块 X 错误。我们遵循了建议 here包括一个需要开发环境中所有模型的初始化程序。

但是,我们看到了同样的错误。还有其他建议吗?我们在下面包含了初始化程序代码,从输出到控制台,看起来代码正在被调用。

我们使用的是 Rails 3.2.12 + Ruby 1.9.3。

if Rails.env == "development"
Dir.foreach("#{Rails.root}/app/models") do |model_name|
puts "REQUIRING DEPENDENCY: #{model_name}"
require_dependency model_name unless model_name == "." || model_name == ".."
end
end

堆栈跟踪:

Processing by DandyController#get_apps as JSON
Parameters: {"category"=>"featured", "country_id"=>"143441", "language_id"=>"EN"}
WARNING: Can't verify CSRF token authenticity
Completed 500 Internal Server Error in 2ms

ArgumentError (undefined class/module App):
app/controllers/dandy_controller.rb:66:in `get_featured_apps'
app/controllers/dandy_controller.rb:50:in `get_apps'


Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/templat
es/rescues/_trace.erb (2.0ms)
Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/templat
es/rescues/_request_and_response.erb (2.0ms)
Rendered C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_dispatch/middleware/templat
es/rescues/diagnostics.erb within rescues/layout (46.0ms)

代码:

def get_featured_apps( country_id )
# Fetch featured apps from cache or from DB
apps = Rails.cache.fetch( 'featured_apps', {:expires_in => 1.days} ) do
logger.info '+++ Cache miss: featured apps'
get_featured_apps_helper country_id
end

# Get sponsored results



apps = get_featured_apps_helper country_id
# Return featured apps
return apps
end

最佳答案

我已经覆盖了 fetch 方法,这对我来说非常有效!

unless Rails.env.production?
module ActiveSupport
module Cache
class Store
def fetch(name, options = nil)
if block_given?
yield
end
end
end
end
end
end

关于ruby-on-rails - 尽管初始化程序中需要模型,但 Rails 3 中未定义的类/模块 X,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15537790/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com