开发者

Yaml::load_file acting different between development and production (Rails)

开发者 https://www.devze.com 2022-12-23 22:30 出处:网络
I am completely stumped at the nature of this problem.开发者_Go百科 We export data from our application into a \'cleaned\' YAML file (stripping out IDs, created_at etc). Then we (will) allow users to

I am completely stumped at the nature of this problem.开发者_Go百科

We export data from our application into a 'cleaned' YAML file (stripping out IDs, created_at etc). Then we (will) allow users to import these files back into the application - it is the import that is completely bugging me out.

In development, YAML::load_file(params[:uploaded_data].local_path) returns an array of YAML::Objects's (and it doesn't matter which of the number of different ways the file could be loaded):

[#<YAML::Object:0x3c63984 @class="Event", @ivars={"attributes"=>{"exception_count"=>"0", "title"=>"Start", "amount"=>"70.00", "colour"=>nil, "repeat_type_id"=>"0", "repeat_interval"=>"1"}}>, etc etc]

Which is very nice, as the attributes also include the (associated model) exceptions that you see an exception_count for.

However on production (rails 2.3.2, running REE 1.8.7 and 1.8.6 for testing, tested on two different production env's, and running production locally) it returns an array of the Objects within the YAML - in this case, Event:

[#<Event title: "Start", amount: #<BigDecimal:3af2640,'0.7E2',4(8)>, repeat_type_id: 0, colour: nil,  repeat_interval: 1, exception_count: 0>, etc etc]

Now this would be just perplexing if it also included the associated model Exception with it - however it doesn't.

Can anyone at all shed some light on why the Yaml parser would behave so differently between production and development?

I'm on rails 2.3.2, running REE 1.8.7; however I've also tested running Ruby 1.8.6 with exactly the same results.

Thanks for any help!


I think this may be caused by cache_classes being set to true in production and in development false. The YAML::load_file method would try to find classes pertaining to these objects and because they haven't been loaded yet will just create them as YAML objects.

Try "loading" the Event class first simply by calling Event and see if that fixes it.

0

精彩评论

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

关注公众号