Skip to content

Instantly share code, notes, and snippets.

@Frank004
Last active August 26, 2016 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Frank004/08f0e07d3cd9df6418f4c3f739ead592 to your computer and use it in GitHub Desktop.
Save Frank004/08f0e07d3cd9df6418f4c3f739ead592 to your computer and use it in GitHub Desktop.
<%= form_tag search_path, method: :get do %>
<%= text_field_tag :q, nil %>
<% end %>
<%= render partial: "search/form_search" %>
# una carpeta en view que diga search y dentro necesitas el index mas el partial del search_form
#lista de resultados
Productos:
<br>
<% @products.each do ||%>
....
<br>
<% end %>
Articulos:
<br>
<% @articles.each do ||%>
....
<br>
<% end %>
Municipios:
<br>
<% @municipalities.each do ||%>
...
<br>
<% end %>
Empresas:
<br>
<% @enterprises.each do ||%>
...
<br>
<% end %>
Categorias:
<br>
<% @categories.each do ||%>
...
<br>
<% end %>
get "search" => "search#index"
class SearchController < ApplicationController
def index
search_word = params[:q]
@products = Product.search(name_cont: search_word).result
@articles = Article.search(name_cont: search_word).result
@municipalities = Municipality.search(name_cont: search_word).result
@enterprises = Enterprise.search(name_cont: search_word).result
@categories = Category.search(name_cont: search_word).result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment