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| %>
Item | |
| |
<%= submit_tag("Submit Form") %> |