Rails - Is there a way to autocomplete with form_tag attribute?

132 Views Asked by At

My search bar is using a form_tag type, and I can search and enter and it will show results, but it will not give autocompletion or suggestions when typing in the search bar.

When the user starts typing, I want it to display usernames.

Here is what I have tried: This view is my application.html.erb and it is on my navbar. I dont know if that is also important.

    <%= form_tag users_path, :autocomplete => "on", :method => 'get', :id => 'users_search' do %>
        <%= text_field_tag :search, params[:search], placeholder:"search members..",style:"width:300px; height:35px;"
        %>
        <%= submit_tag "", :name => nil, :style => "display: none;" %>
    <% end %>

I also tried :autocomplete => :on in the text_field_tag. I'm just not sure how to go about this using form_tag.

Here is the rest of my code that may be important:

User_controller.rb

def index
    @users = User.search(params[:search])
end

User.rb

def self.search(username)
if username
    username.downcase!
    where("username LIKE ?","#{username}%")
else
    all
end

end

0

There are 0 best solutions below