Topic: Validation
I have a field that I need to validate the presence of an entry, but it's from a different model.
Here's the view code...
<%= text_field_with_auto_complete :agency, :code, {:value => @line_item, :size => 31}, :skip_style => true %>
Here's the controller store/checkout
def checkout
@title = "Please enter your information to continue this purchase."
# @cc_processor = Order.get_cc_processor
# @agency_codes = Agency.find(:all)
if request.get?
unless @order.has_been_placed? then
# Save standard form info
logger.info("\n\nNEW ORDER INIT\n\n")
initialize_new_order
else
logger.info("\n\nEXISTING ORDER INIT\n\n")
initialize_existing_order
end
render :layout => 'checkout' and return
elsif request.post?
@agency_title = params[:agency_title]
@agency_code = params[:agency][:code]
@line_itemz = @order.order_line_items.find(:all)
@line_itemz.each do |item|
item.agency_code = @agency_code.strip
item.shipping_total = 0.00
item.save!
end
@line_itemzz = @order.order_line_items.find(:first)
@line_itemzz.shipping_total = 10.95
@line_itemzz.save!
@line_items = @order.order_line_items.find(:all, :conditions => "agency_name = 1")
@line_items.each do |item|
item.agency_title = @agency_title
item.save!
end
do_checkout()
end
end
Basically, I want to make sure that the person has selected a value for the agency code. This agency code gets assigned to the item, and I'm struggling to get it to validate when it's being used in the store controller.
Also, this controller code is hideous, so any advice is appreciated
Zack
Last edited by zreed20 (2009-06-16 14:12:42)