Topic: Why does this code not work in the production environment?
I am hoping someone can shed some light on why I might be having a problem here.
Below is the code I wrote for my application's configuration form. It is based on Ryan Bates's 'Creating Many Models in One Form'.
http://railsforum.com/viewtopic.php?id=1063
My code allows my user to add form elements to add more internet minimums for his shop setup, etc.
The PROBLEM is my code works on my development machine. However, it fails with validation error 'Interment minimum invalid ' when I deploy this application online. I should also point out that Internet_minimums model works, but the validation messages are never passed and I only get the 'Internet minimum invalid' message.
#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>
My question:
Why does this code above work for me on my home development machine and then fails when it is deployed online?
Last edited by bobbyl (2007-07-28 07:29:26)