So I’m having a strange problem with my rails routing, when I go to the apps index path it’s fine but if the index path has any routes it doesn’t work. I have a controller that looks something like:
class ThingsController < ApplicationController
def index
@things = Thing.search params[:q]
end
def show
@thing = Thing.find params[:id]
end
end
Pretty generic in my opinion, the search method takes the :q param as its input, here is my routes:
MyApp::Application.routes.draw do
root :to => "things#index"
resources :things
end
Any thoughts at why this is happening?
You could add a custom route that passes ‘q’ along to the controller:
It will match the top first, then move down if it doesn’t exist. Then you can call params[:q] no problem.