# :before\_filter validate for fields not part of model

**URL:** <https://www.ruby-forum.com/t/before-filter-validate-for-fields-not-part-of-model/166330>\
**Category:** Rails\
**Created:** [April 23, 2009, 10:45pm UTC](https://www.ruby-forum.com/t/before-filter-validate-for-fields-not-part-of-model/166330 "2009-04-23T22:45:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [April 23, 2009, 10:45pm UTC](https://www.ruby-forum.com/t/before-filter-validate-for-fields-not-part-of-model/166330/1 "2009-04-23T22:45:32Z")

</div>

I have created a pre\_validate method and put it in :before\_filter in  
order to make sure that a custom javascript pulldown has been  
selected. I am using a boolean variable as a flag that turns to true  
when a value is selected and I pass this variable using :with and  
submit\_to\_remote:

def pre\_validate  
respond\_to do |format|  
format.js do  
render :update do |page|  
if params[:time\_selected] == ‘false’  
page.replace\_html ‘error’, “You must select a time.”  
end  
end  
end  
end  
end

This way i can render the error using ajax. If there are seemingly no  
problems with this route, my question is this: I also have a custom  
validation method in my model to check if there is a time conflict,  
but this only gets called after I try object.save, so I was wondering  
if it there are any other disadvantages to putting this custom  
validation into a similar :pre\_filter function other than only being  
able to render one error at once. It seems like it might be a waste  
to have to create an object only to have it fail. Why not check if it  
fails in this particular instance first?
