このRailscastに従ってアプリに検索を実装しましたが、検索が送信されるとページが空白になります。
これは私のshow.html.erb
<div class"row">
<div class="span12">
<h1>Resultados para <%= @search.keywords %>: <%= @search.noticias.size %></h1>
</div>
</div>
と私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
終わり
これはhtml出力です:
<h1>Resultados para : 0</h1>
ここで何かばかげたことを見逃していると確信していますが、わかりません
編集
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
keyword
実際には、検索は mongodb に保存されているため、現在のキーワードをモデルに保存して現在の検索モデルを表示した後にのみアプリが検索を実行するため、どこを見逃すことはないと思います
フォーム
<%= 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 %>