26 Jun 2010, 05:14
808463497_r8dpd-m_pragsmall

Tony Spore (4 posts)

I am trying to get the search to show results however after looking and looking I don’t see why I get this error: “Couldn’t find Event with ID=search”

In the Controller it looks like this - def search @events = Event.search(params[:q]) respond_to do |format| format.html @search.html.erb format.xml { render :xml => @events } end end

my Routes look like this - map.resources :events, :collection => { :search => :get }, :member => { :copy => :post }

What am I doing wrong? Thanks!

26 Jun 2010, 05:19
808463497_r8dpd-m_pragsmall

Tony Spore (4 posts)

Here is my log info:

Processing EventsController#show (for 127.0.0.1 at 2010-06-25 22:12:27) [GET] Parameters: {“commit”=>”Search Events”, “id”=>”search”, “q”=>”shortest”} Event Load (0.1ms) SELECT * FROM “events” WHERE (“events”.”id” = 0)

ActiveRecord::RecordNotFound (Couldn’t find Event with ID=search): app/controllers/events_controller.rb:18:in `show’

Rendered rescues/_trace (30.4ms) Rendered rescues/_request_and_response (0.3ms) Rendering rescues/layout (not_found)

26 Jun 2010, 10:51
Cimg0269_pragsmall

Seth Arnold (22 posts)

First, I think the @search.html.erb snippet is out of place; in the code examples, they’ve been giving the # search.html.erb comments as a reminder to the reader what exactly gets rendered.

I believe you need to restart your application before routing changes are integrated into the application. If you haven’t restarted since adding the new search route…

http://localhost:3000/events/search?q=blah

sure looks like a request to load the event with the ID ‘search’.

Hope this helps. :)

26 Jun 2010, 16:07
808463497_r8dpd-m_pragsmall

Tony Spore (4 posts)

Maybe its a bug in my active record- I just wish I understood ruby a bit more. Hence the book. So this is a good exercise for me to learn I guess. But even after multiple restarts it seems to me that it isn’t looking in all the events table in the DB. Is that correct?

`Processing EventsController#show (for 127.0.0.1 at 2010-06-26 09:01:03) [GET] Parameters: {“commit”=>”Search Events”, “id”=>”search”, “q”=>”fish”} Event Load (0.1ms) SELECT * FROM “events” WHERE (“events”.”id” = 0)

ActiveRecord::RecordNotFound (Couldn’t find Event with ID=search): app/controllers/events_controller.rb:18:in show'

27 Jun 2010, 01:34
Cimg0269_pragsmall

Seth Arnold (22 posts)

Because there is a @commit@ piece in the params hash, I’m going to guess this is coming in from a form. (You probably wouldn’t be typing it by hand. :)

Is the view for the form using form_for? If so, it should probably just be using “form_tag” or something similar. Is the submit action of the form hard-coded to the show action?

If those aren’t it, then I suggest pasting the entire view, action, and model code for this, along with the routing, and hope someone with keener eyes can spot the trouble. :)

Good luck

  You must be logged in to comment