im trying to make a simple search on my database from the index action instead of listing all the data
this is my users/index
<%= 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 %>
and this is the find method in my controller:
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
and this are my routes now:
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
the problem is it doesnt go to the :id/edit path… it instead calls the create method which gives a few errors because the validations didnt pass. how do i make it access find method?
You should put the path right in your form_tag.