An Interest In:
Web News this Week
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
April 23, 2021 12:08 pm GMT
Original Link: https://dev.to/yarotheslav/search-field-without-gems-2g94
TLDR - Basic search field with Ruby on Rails
MISSION: field to search for user email that contains characters. Example:
users_controller.rb
def index if params[:email] @users = User.where('email ILIKE ?', "%#{params[:email]}%").order(created_at: :desc) #case-insensitive else @users = User.all.order(created_at: :desc) end end
any view (users/index.html.erb or in a bootstrap navbar)
.form-inline.my-2.my-lg-0 = form_tag(courses_path, method: :get) do .input-group = text_field_tag :title, params[:title], autocomplete: 'off', placeholder: "Find a course", class: 'form-control-sm' %span.input-group-append %button.btn.btn-primary.btn-sm{:type => "submit"} %span.fa.fa-search{"aria-hidden" => "true"}
without bootstrap
<%= form_tag(users_path, method: :get) do %> <%= text_field_tag :email, params[:email], autocomplete: 'off', placeholder: "user email" %> <%= submit_tag "Search" %><% end %>
That's it! Looks nice, doesn't it?
Original Link: https://dev.to/yarotheslav/search-field-without-gems-2g94
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To