开发者

how to unload the files loaded by the "require" statement in rails

I have bunch of clas开发者_C百科ses

files = ["payment_type","payment_type_ticket_mapping","price_modifier_ticket_delta_mapping","user","revenue_type","revenue_type_group","tax","tax_type","punch"]
files.each {|file| require file }

that are required to fulfill the requirement of Marshal.load but when I run the rsepc they give me the following error

/spec/factories.rb:6: undefined method `admin_login_url' for #<ActionView::Base:0xb62e0228> (ActionView::TemplateError)

When I remove that reuire statement it works fine but that statement is necessary for the functionality of Marshal.load how to unload the loaded classes by require statement after the work is done.


I have resolved that problem using the config.cache_classes = true in the environment.


To unload a file just remove all its definitions, and then remove the file name from the loaded file list $", like the following:

$".grep(/#{file}/).each { |f| $".delete(f) }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜