0

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 %>
Luiz E.
  • 6,769
  • 10
  • 58
  • 98
  • 1
    since the railcast you posted is not available to non paying users, can you post the form? Are you maybe missing `Noticia.fulltext_search(params[:keywords])`? – Zippie Apr 10 '13 at 17:25
  • Can you show us the `show` method of your controller as well... I guess you're missing to provide the keywords somehow... – Vapire Apr 10 '13 at 17:26
  • @Vapire edited. Zippie, I explained about the search on my edit – Luiz E. Apr 10 '13 at 17:31
  • 1
    Can you post the form? – Zippie Apr 10 '13 at 17:35
  • 1
    Ok, after paste the form, I got it, it was the name="search[keyword]", it is "keywords". as I said, something stupid :) – Luiz E. Apr 10 '13 at 17:38

0 Answers0