# AWDWR (latest) searc example with REST

**URL:** <https://www.ruby-forum.com/t/awdwr-latest-searc-example-with-rest/70850>\
**Category:** Rails\
**Created:** [October 3, 2006, 2:13pm UTC](https://www.ruby-forum.com/t/awdwr-latest-searc-example-with-rest/70850 "2006-10-03T14:13:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 3, 2006, 2:13pm UTC](https://www.ruby-forum.com/t/awdwr-latest-searc-example-with-rest/70850/1 "2006-10-03T14:13:31Z")

</div>

There’s an example in the book that presents a search form , listing  
users  
and their favorite languages below it. Using the search form text field  
you  
can filter the list by their favorite language.

I did the demo from the book using the same schema and it works.  
However, I’m trying to implement this same thing in my app which uses  
REST  
controllers, and am running into an error when loading the search form.  
The  
error is:

ActiveRecord::RecordNotFound in PositionsController#show  
Couldn’t find Position with ID=search\_position

I’m assuming the issue is in the search action in the controller. The  
list.rhtml should return all the positions. It all looks pretty  
straight  
forward.  
In the controller:

def search  
unless params[:search].blank?  
@position\_pages, @positions = paginate :positions,  
:per\_page =\> 10,  
:order =\> order\_from\_params,  
:conditions =\> Position.conditions\_by\_like(params[:search])  
logger.info @positions.size  
else  
list  
end

```
render :partial => 'search', :layout => false
end

```

I’m showing the get/show in the controller - though I’m not sure if or  
why  
it would intefere with the search action.  
def show  
@position = Position.find(params[:id])

```
respond_to do |format|
  format.html # show.rhtml
  format.xml { render :xml => @position.to_xml }
end

```

end

## Stuart

> **[Dark ambient](https://en.wikipedia.org/wiki/Dark_ambient)**
>
> Dark ambient (referred to as ambient industrial especially in the 1980s) is a genre of post-industrial music that features an ominous, dark droning and often gloomy, monumental or catacombal atmosphere, partially with discordant overtones. It shows similarities with ambient music, a genre that has been cited as a main influence by many dark ambient artists, both conceptually and compositionally. Although mostly electronically generated, dark ambient also includes the sampling of hand-pla 
> The te...

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 3, 2006, 3:09pm UTC](https://www.ruby-forum.com/t/awdwr-latest-searc-example-with-rest/70850/2 "2006-10-03T15:09:40Z")

</div>

I was having a problem like this recently. I believe it’s a problem in  
your routing, because params[:search] is returning ‘search\_position’  
instead of the value you want. Have a look at the params that are being  
received by your action when you call the URL.

Jason

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 3, 2006, 3:15pm UTC](https://www.ruby-forum.com/t/awdwr-latest-searc-example-with-rest/70850/3 "2006-10-03T15:15:40Z")

</div>

On 10/3/06, Jason N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I was having a problem like this recently. I believe it’s a problem in  
> your routing, because params[:search] is returning ‘search\_position’  
> instead of the value you want. Have a look at the params that are being  
> received by your action when you call the URL.
> 
> Jason

Not entirely sure what I’m seeing in the log but this is the select  
statement going out:  
Parameters: {“action”=\>“show”, “id”=\>“search\_position”,  
“controller”=\>“positions”}  
e[4;36;1mUser Columns (0.000000)e[0m e[0;1mSHOW FIELDS FROM  
userse[0m  
e[4;35;1mUser Load (0.000000)e[0m e[0mSELECT \* FROM users WHERE  
(users.`id` = 11 ) LIMIT 1e[0m  
e[4;36;1mPosition Columns (0.000000)e[0m e[0;1mSHOW FIELDS FROM  
positionse[0m  
e[4;35;1mPosition Load (0.000000)e[0m e[0mSELECT \* FROM positions  
WHERE  
(positions.id = 0) e[0m

In the def index action I am filtering show by user. I guess at this  
point  
that is just an aside since /positions will return all the records of  
that  
user and I also can remove that condition. Which didn’t help.  
What I see here is the odd statement "WHERE (positions.id = 0)

Not sure how the routing would effect things. Currently my routes.rb  
are  
fairly simple.

map.resources :users, :sessions, :companies  
map.resources :positions, :member =\> {:description =\> :get}

Stuart

Dark A. wrote:

> > ## Couldn’t find Position with ID=search\_position :order =\> order\_from\_params, why it would intefere with the search action.
> > 
> > [Dark ambient - Wikipedia](http://en.wikipedia.org/wiki/Dark_ambient)
> > 
> > >
> 
> >

–

> **[Dark ambient](https://en.wikipedia.org/wiki/Dark_ambient)**
>
> Dark ambient (referred to as ambient industrial especially in the 1980s) is a genre of post-industrial music that features an ominous, dark droning and often gloomy, monumental or catacombal atmosphere, partially with discordant overtones. It shows similarities with ambient music, a genre that has been cited as a main influence by many dark ambient artists, both conceptually and compositionally. Although mostly electronically generated, dark ambient also includes the sampling of hand-pla 
> The te...

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 3, 2006, 6:28pm UTC](https://www.ruby-forum.com/t/awdwr-latest-searc-example-with-rest/70850/4 "2006-10-03T18:28:10Z")

</div>

On 10/3/06, Dark A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> positionse[0m
> 
> > > I did the demo from the book using the same schema and it works.  
> > > list.rhtml should return all the positions. It all looks pretty  
> > > else  
> > > @position = Position.find(params[:id])
> > > 
> > > >

What I’m seeing here ( i think) is that even though it should be  
accessing  
the search action in the controllers, it’s calling the get / show  
action.  
Hence the problem with the id issue.  
Anyone ?  
This might be a routing issue though right now nothing I’ve tried in  
routes.rb is helping.

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 3, 2006, 11:26pm UTC](https://www.ruby-forum.com/t/awdwr-latest-searc-example-with-rest/70850/5 "2006-10-03T23:26:52Z")

</div>

I took the whole code and moved it out of my restful controller, since I  
can’t quite figure out how to make it work in there. However now that  
it  
has it’s own controller, I’m getting a nil error. Here is the code:

Controller code:  
class PositionController \< ApplicationController  
def search  
unless params[:search].blank?  
@position\_pages, @position = paginate(:positions,  
:per\_page =\> 10,  
:order =\> order\_from\_params,  
:conditions =\> Position.conditions(params[:search]))  
logger.info @positions.size  
else  
list  
end  
render :partial =\> ‘search’, :layout =\> false  
end  
end

The search view  
\<%= start\_form\_tag(‘javascript:void%200’) %\>

Listing users \<%= text\_field\_tag 'search', @search %\>

\<%= observe\_field :search,  
:frequency =\> 0.5,  
:update =\> ‘ajaxWrapper’,  
:complete =\> “Element.hide(‘spinner’)”,  
:before =\> “Element.show(‘spinner’)”,  
:with =\> “‘search=’ +  
encodeURIComponent(value)”,  
:url =\> {:action=\>‘search’, :only\_path =\>  
false}  
%\>

\<%= end\_form\_tag %\>
\<%= render :partial=\>'search' %\>

the \_search partial

\<%= javascript\_include\_tag :defaults %\>

\<% for position in @positions %\> \<----- this is where I’m getting the  
nil  
object. Makes no sense.

\<% end %\>

\<%= link\_to ‘Previous page’,  
{ :page =\> @position\_pages.current.previous } if  
@position\_pages.current.previous %\>  
\<%= link\_to ‘Next page’,  
{ :page =\> @position\_pages.current.next } if  
@position\_pages.current.next %\>

Stuart  
On 10/3/06, Dark A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > instead of the value you want. Have a look at the params that are  
> > > “controller”=\>“positions”}  
> > > point that is just an aside since /positions will return all the records of  
> > > Dark A. wrote:
> > > 
> > > > ```
> > > > unless params[:search].blank?
> > > > end
> > > > end
> > > > 
> > > > ```
> 
> the search action in the controllers, it’s calling the get / show action.  
> Hence the problem with the id issue.  
> Anyone ?  
> This might be a routing issue though right now nothing I’ve tried in  
> routes.rb is helping.
> 
> Stuart

–

> **[Dark ambient](https://en.wikipedia.org/wiki/Dark_ambient)**
>
> Dark ambient (referred to as ambient industrial especially in the 1980s) is a genre of post-industrial music that features an ominous, dark droning and often gloomy, monumental or catacombal atmosphere, partially with discordant overtones. It shows similarities with ambient music, a genre that has been cited as a main influence by many dark ambient artists, both conceptually and compositionally. Although mostly electronically generated, dark ambient also includes the sampling of hand-pla 
> The te...

| Position | Title |
| --- | --- |
| \<%=h position.company.name %\> | \<%=h position.title %\> | \<%= link\_to "Show", search\_position\_path(position) %\> |
