[HELP] Couldn't find Search with id= from controller

I have been working on the search form for my app. The advanced search
works fine, however I am unable to get the regular search form to work.
It should be able to search the entire user database, and I should be
able to string keywords together. For example if I search the term “no
kids” it should return the results for everyone who has “no kids” listed
on their profile. Then if I want to be more advance I can search “no
kids, asian” and this would of course pull up users with Asian ethnicity
that has no kids.

When I do this I get the following error: Couldn’t find Search with
id=kids. It points to the searches controller for the following line:

def index
@search = Search.find(params[:search])

Also a quick note I am following the railscast 111 for this.

cornelius wilson [email protected] wrote:

id=kids. It points to the searches controller for the following line:

def index
@search = Search.find(params[:search])

Also a quick note I am following the railscast 111 for this.

Attachments:
http://www.ruby-forum.com/attachment/8535/searches_controller.rb
http://www.ruby-forum.com/attachment/8536/user.rb
http://www.ruby-forum.com/attachment/8537/search.rb

What’s in the searches table? How are you populating it to do a
Search.find? I’m a wee bit unclear why there’s a Search model at all,
really…

I have it as a model to save all the searches to database. Originally I
thought it would be good to have information on what users are searching
for on a dating app, though I have back away from this in recent weeks.
I just haven’t removed it as I don’t want to break the app.

Searches table has gender, age, children, religion, ethnicity, created
at, updated at.

On 24 June 2013 20:05, cornelius wilson [email protected] wrote:

id=kids. It points to the searches controller for the following line:

def index
@search = Search.find(params[:search])

find expects a numeric id value, presumable params[:search] is set to
“kids” rather than an id.

Colin

Colin L. wrote in post #1113571:

On 24 June 2013 20:05, cornelius wilson [email protected] wrote:

id=kids. It points to the searches controller for the following line:

def index
@search = Search.find(params[:search])

find expects a numeric id value, presumable params[:search] is set to
“kids” rather than an id.

Colin

How would I be able to reverse it so that it searches for the term as
oppose to the numeric id of the search options. As I would like for it
to be able to search all things on a user profile.

Colin L. wrote in post #1113657:

On 26 June 2013 16:01, cornelius wilson [email protected] wrote:

Colin

How would I be able to reverse it so that it searches for the term as
oppose to the numeric id of the search options. As I would like for it
to be able to search all things on a user profile.

I suggest you start by working right through a good tutorial such as
railstutorial.org, which is free to use online. That will show you
the basics of Rails. Also look through the Rails Guides, in
particular the one on ActiveRecordQueryInterface.

Colin

I did that tutorial months ago. I have been able to build inbox
messaging from scratch, which was a challenging task with all the
features a inbox must have especially considering I have no prior coding
experience. I am 90% complete with my app, with the rest being small
fixes such as this basic search form, having users select photo from
gallery as their default profile picture, add user to favorites, and
then the rest is javascript. Directing me to read a tutorial does not
help me in this case. I have been stuck on this trying to figure it out.
Had other people take a look and they too can not spot the problem.

The error is coming from “@search = Search.find(params[:search])” in the
searches controller for def index. I have tried different strings to see
if I can get around it. None have work. One solution I thought would be
best that just failed was moving the def index to the users controller
and combining it with the " @users = User.all" that is already there.
But that did not do anything either.

On 28 June 2013 21:29, cornelius wilson [email protected] wrote:

the basics of Rails. Also look through the Rails Guides, in
then the rest is javascript. Directing me to read a tutorial does not
help me in this case. I have been stuck on this trying to figure it out.
Had other people take a look and they too can not spot the problem.

The error is coming from “@search = Search.find(params[:search])” in the
searches controller for def index.

Can you explain what that line of code is supposed to do?

Colin

On 26 June 2013 16:01, cornelius wilson [email protected] wrote:

Colin

How would I be able to reverse it so that it searches for the term as
oppose to the numeric id of the search options. As I would like for it
to be able to search all things on a user profile.

I suggest you start by working right through a good tutorial such as
railstutorial.org, which is free to use online. That will show you
the basics of Rails. Also look through the Rails Guides, in
particular the one on ActiveRecordQueryInterface.

Colin