:before_filter validate for fields not part of model

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

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.”

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs