Urls with params cause request to be routed to wrong action
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开发者_Python百科 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:
resources :things
map.connect '/things/:q', :controller => :things, :q => :q
root :to => "things#index"
It will match the top first, then move down if it doesn't exist. Then you can call params[:q] no problem.
精彩评论