I am new to Ruby on Rails and I am building my first website. I have a user model with three columns: firstname , lastname and email . I use ransack to create a search engine, and I want to have one search field that will go through each column and display the result.
I did user_controller.rb as follows:
@q = User.search(params[:q]) @users = @q.result(:distinct => true)
And my User \ index.html.erb looks like this:
<%= search_form_for @search do |f| %> <div class="field"> <%= f.label :firstname_cont , "Firstname" %> <%= f.text_field :firstname_cont %> <%= f.label :lastname_cont , "Lastname" %> <%= f.text_field :lastname_cont %> <%= f.label :email_cont , "Email" %> <%= f.text_field :email_cont %> </div> <div class="actions"><%= f.submit "Search" %></div> <% end %>
Providing me with 3 search fields, but I want only the one that goes through the first name, last name and email address.
Edit 1: After testing a few more, I found that the search field could not handle both the name and the name, or any spaces. I read that you can do helper_method as follows: Finding multiple fields with Ransack
And when I get the search result, I fall into my model index, etc .: user / index. Where can I change this?
But there is nothing about how to use it in a view. Why is it so difficult to just start, this is what you do: in Controller do it β in the model do it β in sight do it β And don't forget to fix routes like this β
Remi Champ
source share