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></
</table> <% end %> ========================end new.rhtml file=============================