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

33 views
Skip to first unread message

cornelius wilson

unread,
Jun 24, 2013, 3:05:10 PM6/24/13
to rubyonra...@googlegroups.com
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.

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


--
Posted via http://www.ruby-forum.com/.

Tamara Temple

unread,
Jun 25, 2013, 5:33:30 AM6/25/13
to rubyonra...@googlegroups.com
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...

cornelius wilson

unread,
Jun 25, 2013, 10:22:34 AM6/25/13
to rubyonra...@googlegroups.com
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.

Colin Law

unread,
Jun 25, 2013, 3:57:15 PM6/25/13
to rubyonra...@googlegroups.com
On 24 June 2013 20:05, cornelius wilson <li...@ruby-forum.com> wrote:
> 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])

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

Colin

cornelius wilson

unread,
Jun 26, 2013, 11:01:20 AM6/26/13
to rubyonra...@googlegroups.com
Colin Law wrote in post #1113571:
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 Law

unread,
Jun 26, 2013, 3:27:10 PM6/26/13
to rubyonra...@googlegroups.com
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

cornelius wilson

unread,
Jun 28, 2013, 4:29:38 PM6/28/13
to rubyonra...@googlegroups.com
Colin Law wrote in post #1113657:
> On 26 June 2013 16:01, cornelius wilson <li...@ruby-forum.com> 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.

Colin Law

unread,
Jul 1, 2013, 4:21:18 PM7/1/13
to rubyonra...@googlegroups.com
On 28 June 2013 21:29, cornelius wilson <li...@ruby-forum.com> wrote:
> Colin Law wrote in post #1113657:
>> On 26 June 2013 16:01, cornelius wilson <li...@ruby-forum.com> 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.

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

Colin

> 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.
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/44e3db3bf80f7dde640dbefcdffb5fc3%40ruby-forum.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
Reply all
Reply to author
Forward
0 new messages