# This code doesn't work in production

**URL:** <https://www.ruby-forum.com/t/this-code-doesnt-work-in-production/225960>\
**Category:** Deployment\
**Created:** [July 29, 2007, 3:48pm UTC](https://www.ruby-forum.com/t/this-code-doesnt-work-in-production/225960 "2007-07-29T15:48:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rlorimor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/96bed5/32.png) [@rlorimor](https://www.ruby-forum.com/u/rlorimor)\
**Post date:** [July 29, 2007, 3:48pm UTC](https://www.ruby-forum.com/t/this-code-doesnt-work-in-production/225960/1 "2007-07-29T15:48:37Z")

</div>

The code below works in my development server on my home computer.  
However, the code breaks with a ‘Internet minimum invalid’ validation  
error when deploy to production server.

What could the problem be? HOw might I track down what causing this?

# the code:

#In my shop controller  
def update  
@mins = InternetMinimum.new  
@shop.update\_attributes( params[:shop] )  
@line\_of\_sale = @shop.line\_of\_sales.find( :first, :conditions =\>  
‘type = “InternetRate”’ ) ||  
@line\_of\_sale = InternetRate.new  
@line\_of\_sale.update\_attributes( params[:line\_of\_sale] )  
@line\_of\_sale.name = ‘Internet Rate’ # default if new or old, there  
is only one per shop  
@shop.all\_internet\_minimums.each { |min| min.destroy }  
if params[:internet\_minimums]  
params[:internet\_minimums].each\_value do |min |  
@shop.internet\_minimums.build(min) unless min.values.all?(  
&:blank? )  
end  
end  
Shop.transaction do  
@shop.save!  
@line\_of\_sale.shop = @shop  
@line\_of\_sale.save!  
flash[:notice] = ‘Shop was successfully updated.’  
redirect\_to :action =\> :index  
end  
rescue ActiveRecord::RecordInvalid =\> e  
@line\_of\_sale.valid?  
@shop.valid?  
render :action =\> :setup  
end

#models  
class InternetMinimum \< ActiveRecord::Base

belongs\_to :shop

validates\_presence\_of :minutes, :min\_charge, :message =\> “must be  
present”  
validates\_uniqueness\_of :minutes, :message =\> “must be unique”, :scope  
=\> ‘shop\_id’  
validates\_numericality\_of :minutes, :only\_integer =\> true, :message =\>  
“number only, no other characters allowed”  
validates\_numericality\_of :min\_charge, :message =\> ‘must be a number  
(decimal is OK)’  
validates\_length\_of :minutes, :maximum =\> 4

end

#Inside my view

 \<% @shop.internet\_minimums.each\_with\_index do |mins, index| %\> \<%= render :partial =\> 'set\_field', :locals =\> { :mins =\> mins, :index =\> index } %\> \<% end %\> \<% if @shop.internet\_minimums.size == 0 %\> \<%= render :partial =\> 'set\_field', :locals =\> { :mins =\> @mins, :index =\> 0 } %\> \<% end %\> 
 \<%= render :partial =\> 'add\_set\_link', :locals =\> { :index =\> @shop.internet\_minimums.size + 1 } %\>

#partials  
#\_set\_field.rhtml  
\<% fields\_for “internet\_minimums[#{index}]”, mins do |ff| %\>

- Minutes: \<%= ff.text\_field :minutes, :size =\> 2, :maxlength =\> 4 %\> Minimum Charge: \<%= ff.text\_field :min\_charge, :size =\> 2 %\> \<%= link\_to\_remote 'remove', :url =\> { :action =\> 'remove\_set', :index =\> index } %\>
\<% end %\>

#\_add\_set\_link.rhmtl

\<%= link\_to\_remote 'add minimum set', :url =\> { :action =\> 'add\_set', :index =\> index } %\>

==========

---

<div class="post-metadata">

**Author:** ![rlorimor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/96bed5/32.png) [@rlorimor](https://www.ruby-forum.com/u/rlorimor)\
**Post date:** [July 30, 2007, 12:03am UTC](https://www.ruby-forum.com/t/this-code-doesnt-work-in-production/225960/2 "2007-07-30T00:03:25Z")

</div>

Are you able to reproduce it with tests or specs? Are the same  
versions of Ruby and Rails installed?

On a side note, you might consider reading up on skinny controllers,  
fat models.

Here are a few links…

[http://www.robbyonrails.com/articles/2007/06/19/put-your-controllers-](http://www.robbyonrails.com/articles/2007/06/19/put-your-controllers-)  
on-a-diet-already

Good luck!

Robby

On Jul 29, 2007, at 6:48 AM, Robert L. wrote:

> def update  
> params[:internet\_minimums].each\_value do |min |  
> end
> 
> # validates\_length\_of :minutes, :maximum =\> 4 \<%= render :partial =\> ‘set\_field’, :locals =\> { :mins =\> @mins, :size =\> 2, :maxlength =\> 4 %\>
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Robby R.  
Founder and Executive Director

PLANET ARGON, LLC  
Design, Development, and Hosting with Ruby on Rails

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://www.robbyonrails.com/](http://www.robbyonrails.com/)

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]

---

<div class="post-metadata">

**Author:** ![rlorimor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/96bed5/32.png) [@rlorimor](https://www.ruby-forum.com/u/rlorimor)\
**Post date:** [July 30, 2007, 7:48am UTC](https://www.ruby-forum.com/t/this-code-doesnt-work-in-production/225960/3 "2007-07-30T07:48:29Z")

</div>

Robby, thanks for replying.

My development setup is:

Ubuntu 7.04 Feisty Fawn  
ruby 1.8.5  
rails 1.2.3  
mongrel 1.0.1 #I use mongrel for my development server  
MySQL 5+

On my production server:

Ubuntu 6.10 LTS Dapper  
ruby 1.8.6 #Initial this was ruby 1.8.4, see notes below  
rails 1.2.3  
mongrel 1.0.1  
apache 2.2  
MySQL 5+

The first thing I tried to fix this was rebuild my VPS slice to have the  
latest ruby 1.8.6 instead of the default ruby 1.8.4. Ubuntu Server  
Dapper install ruby 1.8.4 by default. Feisty Fawn install 1.8.5 by  
default.

There server was built with Mike B.'s Deprec for Capistrano. Inside  
the recipe, I found these apt-get packages:

build-essential ntp-server mysql-server wget ruby irb ri rdoc  
ruby1.8-dev libopenssl-ruby libmysql-ruby zlib1g-dev zlib1g openssl  
libssl-dev subversion

The next thing I am going to try to is write some tests to see if it  
breaks locally.

If I had to guess, I would say the “.build” method is not working on  
production server. I can’t find any documentation on this method.

Note that the server use apache to server the pages. Could that be the  
problem in some way?

---

<div class="post-metadata">

**Author:** ![rlorimor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/96bed5/32.png) [@rlorimor](https://www.ruby-forum.com/u/rlorimor)\
**Post date:** [August 17, 2007, 1:52pm UTC](https://www.ruby-forum.com/t/this-code-doesnt-work-in-production/225960/4 "2007-08-17T13:52:33Z")

</div>

Robert L. wrote:

> The next thing I am going to try to is write some tests to see if it  
> breaks locally.

Tests will almost assuredly help you find the root of this problem  
faster than we can. Probably the easiest way would be to run  
error\_messages\_for(‘mins’) in your view.

> If I had to guess, I would say the “.build” method is not working on  
> production server. I can’t find any documentation on this method.

This seems unlikely, .build has been around for some time. For some very  
breif documentation, search for build on this page:

> **[ActiveRecord::Associations::ClassMethods](https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#M000642)**
>
> Associations are a set of macro-like class methods for tying objects together through foreign keys.

---

<div class="post-metadata">

**Author:** ![rlorimor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/96bed5/32.png) [@rlorimor](https://www.ruby-forum.com/u/rlorimor)\
**Post date:** [August 18, 2007, 1:41pm UTC](https://www.ruby-forum.com/t/this-code-doesnt-work-in-production/225960/5 "2007-08-18T13:41:21Z")

</div>

I solved this problem, though I am not 100% sure how I fixed.

In the process of writing test, I decided to remove an feedtool gem I  
was also having problems with. The code now works just as it does on my  
development server.

Thanks to everyone who tried to help.
