Question: I am trying to move recursively through each Node in a List class to find if a certain integer exists in one of the Nodes in the list. 

This is my header file:

```
class List
{
public:
    bool find(int d) const { return false; }
private:
    Node *head;

    bool findNode(const Node*, int) const;
};

```

Here is the code for two functions:

```
bool List::find(int d) const
{
    return findNode(head, d);
}

bool List::findNode(const Node* n, int d) const
{
    if (n == NULL)
        return false;
    else if (n->data == d)
        return true;
    else
        findNode(n->next, d);
}

```

Now here's my question: Did I doom myself by adding the `if (n == NULL)` statement in the `findNode` function so that it always returns false? I don't think I need to do that if I already have `return false` in the header file. Should I remove that line, and is there a better way to do this?

Answer: 
This can definitely be done. You can use the standard rails form or the [`simple_form`](https://github.com/plataformatec/simple_form) gem to do this.

For example if you had categories and items to display, your standard rails form would look like this: 

```
<%= form_for @item do |f| %>

    <%= f.grouped_collection_select(:category_id, Category.order(:name), 
                          :items, :name, :id, :title, 
                          include_blank: "Please Choose...") %>
<% end %>

```

This displays the main categories, and then the subcategories (items in this case) in each category. Its output looks like this, in which `accessories, canon camera` etc are the main categories, and `manfrotto tripod, canon 5D3` are the sub categories.:

[![Category1](https://i.stack.imgur.com/XVcj5.png)](https://i.stack.imgur.com/XVcj5.png)

It is similar to the html `optgroup` tag which looks like this:

```
<select>
 <optgroup label="Group 1">
   <option>Option 1.1</option>
 </optgroup> 
 <optgroup label="Group 2">
   <option>Option 2.1</option>
   <option>Option 2.2</option>
 </optgroup>
 <optgroup label="Group 3" disabled>
   <option>Option 3.1</option>
   <option>Option 3.2</option>
   <option>Option 3.3</option>
 </optgroup>
</select>

```

Which produces: 

[![Category2](https://i.stack.imgur.com/9cY5b.png)](https://i.stack.imgur.com/9cY5b.png)

Obviously you would have to modify this to fit your project, but it can definitely be achieved.
For more flexible adjustment you can use select2 <https://select2.github.io>