# Why isn't validation kicking in and how can I make it so?

**URL:** <https://www.ruby-forum.com/t/why-isnt-validation-kicking-in-and-how-can-i-make-it-so/127774>\
**Category:** Rails\
**Created:** [February 1, 2008, 6:43am UTC](https://www.ruby-forum.com/t/why-isnt-validation-kicking-in-and-how-can-i-make-it-so/127774 "2008-02-01T06:43:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 1, 2008, 6:43am UTC](https://www.ruby-forum.com/t/why-isnt-validation-kicking-in-and-how-can-i-make-it-so/127774/1 "2008-02-01T06:43:30Z")

</div>

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| %\>

 \<%= 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 %\> 

| Item | |
| 

| 
 \<%= render :partial =\> 'ec\_line\_item', :collection =\> @ec\_order.ec\_line\_items %\> 
 \<%= add\_prescription\_link "Add a prescription" %\> |

 |
| \<%= submit\_tag("Submit Form") %\> |

\<% end %\> ========================end new.rhtml file=============================
