laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org
2008-Feb-01 05:43 UTC
Why isn''t validation kicking in and how can I make it so?
Hi, I have a model, ec_order, which has multiple ec_line_items. You start a "new" order through the OrderController ... class OrderController < ApplicationController def new if logged_in? @user = User.find(session[:user_id]) @ec_order = EcOrder.new 3.times { @ec_order.ec_line_items.build } else flash[:notice] = "You must be logged in to access this page." redirect_to :controller => "register", :action => "start" end end def summary @ec_order = EcOrder.new(params[:ec_order]) session[:ec_order] = @ec_order end ... end Here''s the ec_line_item model: class EcLineItem < ActiveRecord::Base belongs_to :ec_order validates_numericality_of :prescription_number, :integer_only => true end In the form on the "new" view, you submit to the "summary" action. How can I detect if the ec_line_item objects are valid or not and reroute back to the "new" action? Thanks, - Dave PS - If it''s useful, here''s the app/views/order/new.rhtml file: ===================Begin new.rhtml file============================<% form_for :ec_order, :url => ''summary'' do |f| %> <table> <tr> <td>Item</td> <td></td> </tr> <%= f.hidden_field :ship_first_name, :value => @user.ship_to_first_name %> <%= f.hidden_field :ship_last_name, :value => @user.ship_to_last_name %> <%= f.hidden_field :ship_street_address, :value => @user.ship_to_street %> <%= f.hidden_field :ship_city, :value => @user.ship_to_city %> <%= f.hidden_field :ship_state, :value => @user.ship_to_state %> <%= f.hidden_field :ship_zip, :value => @user.ship_to_zip %> <%= f.hidden_field :ship_country, :value => @user.ship_to_country %> <%= f.hidden_field :email, :value => @user.email %> <%= f.hidden_field :phone, :value => @user.phone %> <tr><td> <table cellpadding="0" cellspacing="0" border="0"> <tr><td> <div id="ec_line_items"> <%= render :partial => ''ec_line_item'', :collection => @ec_order.ec_line_items %> </div> <%= add_prescription_link "Add a prescription" %> </td></tr> </table> </td></tr> <tr><td align="center"><%= submit_tag("Submit Form") %></td></ tr> </table> <% end %> ========================end new.rhtml file============================--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---