Reputation: 1
I want to a searching function for users. It does not work. So I simplified the method, I just want to refresh the index page when I hit the search button. But it still does not work, it said ActiveRecord::RecordNotFound in UsersController#show, Couldn't find User with id=search.
please tell me Why
my controller
class UsersController < ApplicationController
load_and_authorize_resource :except => [:index]
def search
redirect_to users_path
end
end
My view
<%= form_tag users_search_path, :method => 'get' do %>
<td><%= text_field_tag :username, params[:username] %></td>
<%= submit_tag "Search", :class => "buttons buttons-rounded buttons-flat-action", :id => "button-new"%>
<br><br><br>
<% end %>
My Route
Procedures::Application.routes.draw do
devise_for :users
#### USER MANAGEMENT ####
resources :users do
resources :rateofpays # professional timesheet
resources :roles
resources :biographies
resources :qualifications do
collection do
put 'complete', :action => 'complete'
end
end
resources :supervisors
end
#### users search ####
get 'users/search' => "users#search", as: 'users_search'
Upvotes: 0
Views: 1023
Reputation: 36860
The line
get 'users/search' => "users#search", as: 'users_search'
...is too far down in your routes. the resources :users
appears first, and it has a match path that looks like users/:id
and the users/search
is incorrectly matching against that.
Just move the get 'users/search'
to the top... or alternatively define it as a collection method under resources :users
resources :users do
collection do
get 'search'
end
Upvotes: 3