Forum: Rails deployment This code doesn't work in production

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Robert L. (Guest)
on 2007-07-29 17:48
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
  <ol id="min_sets">
  <% @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 %>
  </ol>
  <%= render :partial => 'add_set_link', :locals => { :index =>
@shop.internet_minimums.size + 1 } %>

#partials
#_set_field.rhtml
<% fields_for "internet_minimums[#{index}]", mins do |ff| %>
  <li id="min_set_<%= index %>">Minutes: <%= ff.text_field :minutes,
:size => 2, :maxlength => 4 %>
  Minimum Charge: <%= ff.text_field :min_charge, :size => 2 %>
   <small><%= link_to_remote 'remove', :url => { :action =>
'remove_set', :index => index } %></small></li>
<% end %>

#_add_set_link.rhmtl
<p id="add_set_link">
  <%= link_to_remote 'add minimum set',
      :url => { :action => 'add_set', :index => index } %>
</p>
==========
Robby R. (Guest)
on 2007-07-30 02:03
(Received via mailing list)
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/pu...
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/.
>
> >

--
Robby R.
Founder and Executive Director

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

http://www.planetargon.com/
http://www.robbyonrails.com/

+1 503 445 2457
+1 877 55 ARGON [toll free]
+1 815 642 4068 [fax]
Robert L. (Guest)
on 2007-07-30 09:48
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?
Eli M. (Guest)
on 2007-08-17 15:52
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:
http://api.rubyonrails.org/classes/ActiveRecord/As...
Robert L. (Guest)
on 2007-08-18 15:41
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.
This topic is locked and can not be replied to.