我试图从索引操作对我的数据库进行简单搜索,而不是列出所有数据
这是我的用户/索引
<%= form_tag do %>
<fieldset>
<div class="row">
<div class="span5 offset3">
<h2>Enter the CPF number of the user to be managed: </h2></br></br></br>
<div>
<%= label_tag :cpf_no, 'CPF Number:' ,class:"left_align" %>
<%= number_field_tag :cpf_no, params[:cpf_no] %>
</div>
<div>
<%= button_to " Find ", users_find_path , class: "btn btn-large btn-primary" %></br></br>
</div>
</div>
</div>
</fieldset>
<% end %>
这是我的控制器中的查找方法:
class UsersController < ApplicationController
...
def find
if request.post?
@user = user.find_by_cpf_no(params[:cpf_no])
redirect_to edit_user_path(@user.id)
end
end
...
end
这是我现在的路线:
root / home#index
login GET /global/login(.:format) sessions#new
POST /global/login(.:format) sessions#create
logout DELETE /global/logout(.:format) sessions#destroy
users_find POST /global/users/find(.:format) users#find
users GET /global/users(.:format) users#index
POST /global/users(.:format) users#create
new_user GET /global/users/new(.:format) users#new
edit_user GET /global/users/:id/edit(.:format) users#edit
user GET /global/users/:id(.:format) users#show
PUT /global/users/:id(.:format) users#update
DELETE /global/users/:id(.:format) users#destroy
fields GET /global/data(.:format) fields#index
POST /global/data(.:format) fields#create
new_field GET /global/data/new(.:format) fields#new
edit_field GET /global/data/:id/edit(.:format) fields#edit
field GET /global/data/:id(.:format) fields#show
PUT /global/data/:id(.:format) fields#update
DELETE /global/data/:id(.:format) fields#destroy
问题是它没有进入 :id/edit 路径...而是调用了 create 方法,该方法给出了一些错误,因为验证没有通过。我如何让它访问查找方法?