Solved search issue under sinatra-boilerplate.

I discovered something odd about Sinatra routes.

In modularizing my application I managed to break the search feature. If you checkout the master branch and run `ruby library.rb` the search will work.

However, if you checkout the modularize branch and run `ruby main.rb` the search will not work. I figured out why, but I'm not sure what the answer means.

On the master branch in library.rb the order that the routes occur is like this:

get '/'
get '/sort/:sortorder'
get '/search'
get '/add'
post '/'
get '/:id'
put '/:id'
get '/:id/delete'
delete '/:id'

On the modularize branch in main.rb the controllers are all loaded via this statement:

Dir["./app/controllers/*.rb"].each { |file| require file }

I am guessing that the order is the order the controller files appear:

add.rb (/add and  post /)
delete.rb (get /:id/delete  and  delete /:id)
edit.rb (get /:id  and  put /:id)
index.rb (get /)
search.rb (get /search)
sort.rb (get /sort/:sortorder)

Making the route order look like this:

get '/add'
post '/'
get '/:id/delete'
delete '/:id'
get '/:id'
put '/:id'
get '/'
get '/search'
get '/sort/:sortorder'

By putting some `puts` into my code I can see that when I do a search I end up in the get '/:id' in edit.rb. I think what is happening is that the edit route (get '/:id) is somehow grabbing the get '/search' route. At any rate, the puts in search.rb never gets fired.

By changing the edit URLs to be /:id/edit the search starts working again. The ':id' from the edit route is capturing 'search'. Really odd.

I guess I'll have to be more careful about naming routes.