# Validates preference of at least one param

**URL:** <https://www.ruby-forum.com/t/validates-preference-of-at-least-one-param/182445>\
**Category:** Rails\
**Created:** [January 28, 2010, 7:51am UTC](https://www.ruby-forum.com/t/validates-preference-of-at-least-one-param/182445 "2010-01-28T07:51:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [January 28, 2010, 7:51am UTC](https://www.ruby-forum.com/t/validates-preference-of-at-least-one-param/182445/1 "2010-01-28T07:51:27Z")

</div>

I have a simple RESTful search scaffold that finds data in a separate  
model and controller.

```auto
<h1>New search</h1>

<% form_for(@search) do |f| %>
  <%= f.error_messages %>

  <p>
    <%= f.label :category_id %><br />
    <%= f.collection_select :category_id, Category.all, :id, :name,
:include_blank => true %>
  </p>
  <p>
    Age Range<br />
    <%= f.text_field :minimum_age, :size => 3 %> -
    <%= f.text_field :maximum_age, :size => 3 %>
  </p>

  <p>
    <%= f.submit 'Create' %>
  </p>
<% end %>
```

I would like to require at least one parameter in the search, be it a  
selected category, a minimum age, or a maximum age.

---

<div class="post-metadata">

**Author:** ![df-sean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@df-sean](https://www.ruby-forum.com/u/df-sean)\
**Post date:** [January 28, 2010, 4:15pm UTC](https://www.ruby-forum.com/t/validates-preference-of-at-least-one-param/182445/2 "2010-01-28T16:15:30Z")

</div>

Sean S. wrote:

> I have a simple RESTful search scaffold that finds data in a separate  
> model and controller.
> 
> ```auto
> <h1>New search</h1>
> > 
> > <% form_for(@search) do |f| %>
> > <%= f.error_messages %>
> > 
> > <p>
> > <%= f.label :category_id %><br />
> > <%= f.collection_select :category_id, Category.all, :id, :name,
> > :include_blank => true %>
> > </p>
> > <p>
> > Age Range<br />
> > <%= f.text_field :minimum_age, :size => 3 %> -
> > <%= f.text_field :maximum_age, :size => 3 %>
> > </p>
> > 
> > <p>
> > <%= f.submit 'Create' %>
> > </p>
> > <% end %>
> ```
> 
> I would like to require at least one parameter in the search, be it a  
> selected category, a minimum age, or a maximum age.

Then write a custom validation method.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
