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
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:
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:
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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.