# Different behavior between production and development environments?

**URL:** <https://www.ruby-forum.com/t/different-behavior-between-production-and-development-environments/151501>\
**Category:** Rails\
**Created:** [October 22, 2008, 7:24am UTC](https://www.ruby-forum.com/t/different-behavior-between-production-and-development-environments/151501 "2008-10-22T07:24:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![troy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/85f322/32.png) [@troy](https://www.ruby-forum.com/u/troy)\
**Post date:** [October 22, 2008, 7:24am UTC](https://www.ruby-forum.com/t/different-behavior-between-production-and-development-environments/151501/1 "2008-10-22T07:24:03Z")

</div>

I have a yaml file that I am trying to import. If I am in the  
development environment it works perfectly, but when I am in the  
production environment it fails.

The line “records = YAML::load( params[:importfile] )” is where things  
get weird.

production environment gets this "#\<Contract sdc\_ref: “ST-20080515”,  
description: “8x…”

development environment gets this “#\<YAML::Object:0xb6373744  
@ivars={“attributes”=\>{“discount\_ce\_day”=\>0…”

So “contract\_ary.ivars[‘attributes’].update(options)” works in the  
development environment but fails in the production environment.

Can anyone please tell me why this is happening?

Ubuntu 8.04  
ruby 1.8.6  
rails 2.1.1

Thanks

##import\_controller.rb  
def create()  
debugger  
records = YAML::load( params[:importfile] ) #\<\< Problem occurs  
here  
#Separate out the data

```
contract_ary = records[0]
line_items_ary = records[1..-1]
aryAcct = params[:account_id].split('|')
arySales = params[:sales_office].split('|')
arySupport = params[:support_office].split('|')
options = {'account_id' => aryAcct[0], 'account_name' =>

```

aryAcct[1], ‘sales\_rep\_id’ =\> params[:sales\_rep\_id], ‘sales\_office’ =\>  
arySales[0], ‘sales\_office\_name’ =\> arySales[1], ‘support\_office’ =\>  
arySupport[0], ‘support\_office\_name’ =\> arySupport[1], ‘platform’ =\>  
params[:platform], ‘contract\_type’ =\> params[:contract\_type]}  
contract\_ary.ivars[‘attributes’].update(options)

```
#Cleanup
records = nil

#Save new contract
if params[:contract] != ""
  @contract = Contract.find(params[:contract])
  @contract.hw_support_level_id = contract_ary.ivars['attributes']

```

[‘hw\_support\_level\_id’]  
@contract.sw\_support\_level\_id = contract\_ary.ivars[‘attributes’]  
[‘sw\_support\_level\_id’]  
@contract.updates = contract\_ary.ivars[‘attributes’][‘updates’]  
@contract.said = contract\_ary.ivars[‘attributes’][‘said’]  
else  
@contract = Contract.new(contract\_ary.ivars[‘attributes’])  
end

```
#if Contract successfully saves then import
#associated line items
if @contract.save
  line_items_ary.each do |item|
    @line_item =

```

@contract.line\_items.new(item.ivars[‘attributes’])  
@line\_item.save  
end  
end

```
respond_to do |format|
  if !@contract.new_record?
    flash[:notice] = 'Contract was successfully created.'
    format.html { redirect_to(@contract) }
    format.xml { render :xml => @contract, :status

```

=\> :created, :location =\> @contract }  
else  
flash[:notice] = ‘Contract was not successfully created.’  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @contract.errors, :status  
=\> :unprocessable\_entity }  
end  
end  
end

## YAML file to import

- !ruby/object:Contract  
attributes:  
sdc\_ref: ST-20080515  
said: ABC Co.  
description: 8x rp34xx, 2x rx2620, rx3600, EVA8K  
cust\_po\_num: 243422  
payment\_terms: Quarterly  
revenue: 108933.323333333  
annual\_hw\_rev: 73904.9294117647  
annual\_sw\_rev: 2989.18117647059  
annual\_ce\_rev: 0  
annual\_sa\_rev: 0  
annual\_dr\_rev: 0  
start\_date: 8/1/2008  
end\_date: 12/31/2009  
multiyr\_end: 8/1/2009  
hw\_support\_level\_id: SDC 24x7  
sw\_support\_level\_id: SDC SW 24x7  
updates: Yes  
ce\_days: 0  
sa\_days: 0  
discount\_pref\_hw: 0.3  
discount\_pref\_sw: 0.3  
discount\_pref\_srv: 0  
discount\_prepay: 0.05  
discount\_multiyear: 0  
discount\_ce\_day: 0  
discount\_sa\_day: 0
- !ruby/object:LineItem  
attributes:  
support\_type: HW  
product\_num: LABEL  
serial\_num:  
description: HPORAPPQ  
begins: 12:00:00 AM  
ends: 12:00:00 AM  
qty:  
list\_price:  
position: 1  
support\_provider: XYZ
- !ruby/object:LineItem  
attributes:  
support\_type: HW  
product\_num: A9953A  
serial\_num: USL530SKTB  
description: rp3440 PA8900 1GHz 1 Way Server  
begins: 2/1/2009  
ends: 12/31/2009  
qty: 1  
list\_price: 105  
position: 2  
support\_provider: XYZ

---

<div class="post-metadata">

**Author:** ![troy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/85f322/32.png) [@troy](https://www.ruby-forum.com/u/troy)\
**Post date:** [October 22, 2008, 1:54pm UTC](https://www.ruby-forum.com/t/different-behavior-between-production-and-development-environments/151501/2 "2008-10-22T13:54:45Z")

</div>

Even more specifically, it happens when config.cache\_classes = true.  
Other caching has no effect. Is there a way to turn class caching off  
for just this one class/action?

Thanks

---

<div class="post-metadata">

**Author:** ![troy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/85f322/32.png) [@troy](https://www.ruby-forum.com/u/troy)\
**Post date:** [October 23, 2008, 4:37am UTC](https://www.ruby-forum.com/t/different-behavior-between-production-and-development-environments/151501/3 "2008-10-23T04:37:57Z")

</div>

On 22 Oct 2008, at 07:53, Troy wrote:

> Even more specifically, it happens when config.cache\_classes = true.  
> Other caching has no effect. Is there a way to turn class caching off  
> for just this one class/action?

Your YAML file contains serialized ruby objects - the !ruby/  
object:LineItem bits indicate that.  
In dev mode, constants are removed after requests (this is part of the  
reloading of source in dev mode, which is exactly what  
config.cache\_classes does).  
Odds are that when you hit your create action the LineItem and  
Contract classes have not yet been loaded. YAML’s loading does not  
apparently hit const\_missing so when it sees a constant (ie Contract)  
that does not exist you just get something generic (ie YAML::Object).  
In production mode classes are never cleared out like this so unless  
the server is serving its very first request odds are the Contract  
class is loaded so you get back an instance of Contract. YAML::Object  
has an ivars method that gets you something like a hash of instance  
variables, but other objects don’t (everyone has instance\_variable\_get  
though, but that’s not very nice)

It is the dev mode behavious which is weird, you can work around it by  
using require\_dependency to load contract, line\_item and whatever else  
you need. Personally I wouldn’t store the active record objects  
themselves - just their hash of attributes.

Fred

---

<div class="post-metadata">

**Author:** ![troy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/85f322/32.png) [@troy](https://www.ruby-forum.com/u/troy)\
**Post date:** [October 24, 2008, 5:21am UTC](https://www.ruby-forum.com/t/different-behavior-between-production-and-development-environments/151501/4 "2008-10-24T05:21:36Z")

</div>

Thanks Fred, that makes perfect sense now. Now I can turn the  
cache\_classes back on.

On Oct 22, 9:23 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
