I followed this railscast to implement search on my app, but when the search is submited, the page is rendered blank.
This is my show.html.erb
<div class"row">
<div class="span12">
<h1>Resultados para <%= @search.keywords %>: <%= @search.noticias.size %></h1>
</div>
</div>
and my search.rb
class Search
include Mongoid::Document
include Mongoid::Timestamps
field :keywords, type: String
def noticias
@noticias ||= find_news
end
private
def find_news
noticia = Noticia.fulltext_search(keywords)
noticia
end
end
and this is the html output:
<h1>Resultados para : 0</h1>
I'm pretty sure that I'm missing something stupid here, but I can't see
EDIT
search_controller.rb
class SearchesController < ApplicationController
def new
@search = Search.new
end
def create
@search = Search.create!(params[:search])
redirect_to @search
end
def show
@search = Search.find params[:id]
end
end
actually, the searches are beign saved on mongodb, so I don't think I miss keyword
anywhere, because the app only do the search after I save the current keywords to the model and show the current Search model
The form
<%= form_for Search.new, :html => { :class => "navbar-search pull-right"} do |f| %>
<input type="text" class="span2 search-query" placeholder="Pesquisar notícias" name="search[keyword]">
<% end %>