Question: I've got a search working for my application however it only works for the first page when I click next page I get the following error: 

[![enter image description here](https://i.stack.imgur.com/R9mV1.png)](https://i.stack.imgur.com/R9mV1.png)

I've the following code in my vehicles controller: 

```
 def search
  vehicles = Vehicle.fuzzy_search(params[:search_string])
  @vehicles = Kaminari.paginate_array(vehicles.order:make).page(params[:page]).per(3)
  if @vehicles.empty?
    flash.now[:alert] = "No records found - displaying all records ..."
    @vehicles = Vehicle.order(:make).page(params[:page]).per(3)
  end
  render :action => "index"
 end

```

I've got the following code in my vehicle.rb 

```
def self.fuzzy_search(search_string)
    search_string = "%" + search_string + "%"
    self.where("make LIKE ?", search_string)
end

```

and my routes.rb has the following:

```
get 'vehicles/search', to: 'vehicles#search'
post 'vehicles/search', to: 'vehicles#search'

```

For some reason its trying to show a record which is called "search" rather then displaying the second page. I've spend hours trying to figure out why its doing this can someone please help! 

Edit --
Full Trace 
[![enter image description here](https://i.stack.imgur.com/bIz01.png)](https://i.stack.imgur.com/bIz01.png)
[![enter image description here](https://i.stack.imgur.com/KNXyp.png)](https://i.stack.imgur.com/KNXyp.png)

Answer: 
**Exact Problem:**

If you see your error, it is pointing to **`VehicleController#show`**

It is happening because `get 'vehicles/search'` is going to show action but not `search`

Show will be something like,

`get '/vehicles/:id', to: 'vehicles#show'`, so the search it is thiniking as Id and giving you error.

**Solution:**

Move
 `get 'vehicles/search', to: 'vehicles#search'`
above `resources: vehicles`

**Your search route should be on the top of vehicles show route**

So, your routes should be something like,

**routes.rb excerpt:**

```
get 'vehicles/search', to: 'vehicles#search'
post 'vehicles/search', to: 'vehicles#search'
resources: vehicles

```
If you are searching for a single record use -

```
Vehicle.find_by_id(params[:id])

```

If you are trying to find multiple records use -

```
Vehicle.where(id: params[:id])

```

instead of -

```
Vehicle.find(params[:id])

```

This will return Nil if the id you are searching for is not present and will not throw - Record not found error