# A bit lost , could use some direction

**URL:** <https://www.ruby-forum.com/t/a-bit-lost-could-use-some-direction/71349>\
**Category:** Rails\
**Created:** [October 7, 2006, 2:18pm UTC](https://www.ruby-forum.com/t/a-bit-lost-could-use-some-direction/71349 "2006-10-07T14:18:06Z")\
**Posts on this page:** 9\
**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 7, 2006, 2:18pm UTC](https://www.ruby-forum.com/t/a-bit-lost-could-use-some-direction/71349/1 "2006-10-07T14:18:06Z")

</div>

I’m working on a database search and using a search model object.  
Currently, the searches/new.rhtml works well as far as saving the  
parameters  
to the searches table. I think the query is not really working and when  
I  
redirect back to list the results all I get is a nil.to\_sym error.

Let me show my code, first in the controller:

def create  
@search = Search.new(params[:search]) # this saves the selected  
parameters to the database  
#all this pq stuff is really just find statements, however I’m  
using a  
search plugin called criteria\_query  
#but all these pq statement translate to find  
pq = Position.query  
pq.category\_id\_eq(params[:category\_id]) if params[:category\_id]  
pq.state\_id\_eq(params[:state\_id]) if params[:state\_id]  
pq.term\_id\_eq(params[:term\_id]) if params[:term\_id]  
pq.title\_eq(params[:title]) if params[:title]  
pq.city\_eq(params[:city]) if params[:city]

```
 # btw , this is a restful setup
 respond_to do |format|
 if @search.save
 flash[:notice] = 'Position was successfully created.' # so it is 

```

saving  
correctly

```
 format.html { redirect_to searches_url(pq) } # here i'm redirecting

```

back to the index url  
#here i’m just leaving out the other format code (xml, etc)  
end

I’m a bit unsure of how to pass the pq parameters to the index , and  
wonder  
if I’ve set the form up correctly.  
As an example here is one element from the form and the form tags:

\<% form\_for(:search, :url =\> searches\_path) do |f| %\>  
\<%= text\_field(:search,:title) %\>  
\<%= submit\_tag “Create” %\>

So , yeah I’m pretty much new to setting a search up 🙂 and appreciate  
any  
suggestions.  
TIA  
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 7, 2006, 10:30pm UTC](https://www.ruby-forum.com/t/a-bit-lost-could-use-some-direction/71349/2 "2006-10-07T22:30:44Z")

</div>

Starting over on this post:

I’m trying to set up a database search. My controllers name is Searches  
and  
the model is Search.  
I’m using a restful design.

In - def create  
@search = Search.new(params[:search])  
…

end  
This captures the parameters to the database as a saved search. That’s  
working, but after save I am redirecting back to the index page and want  
only to display what’s been asked for in the search form. I’m unsure  
though  
how to grab those parameters.

Can I pass the @search params back to the index page and use them in a  
select statement ?

Also, do I have to do anything special in my form ?

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 8, 2006, 12:49am UTC](https://www.ruby-forum.com/t/a-bit-lost-could-use-some-direction/71349/3 "2006-10-08T00:49:10Z")

</div>

On 10/7/06, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m not entire sure what the problem is, although it sounds to me that  
> what you want to do is somthing like
> 
> redirect\_to :action =\> :search, :id =\> @search.id

Well the action is not search because I’m using a restful controller so  
it’s  
the GET method on the index action which I can call  
with “redirect\_to searches\_url(@search)”.

and then in your search action

> @search = Search.find params[:id}  
> #do something with @search
> 
> That said I’m not sure whether I’m telling you something you already  
> know (sorry if I am) or not

No, I mean it’s starting to sink in.  
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 8, 2006, 2:05am UTC](https://www.ruby-forum.com/t/a-bit-lost-could-use-some-direction/71349/4 "2006-10-08T02:05:14Z")

</div>

On 10/7/06, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m not entire sure what the problem is, although it sounds to me that  
> what you want to do is somthing like
> 
> redirect\_to :action =\> :search, :id =\> @search.id
> 
> and then in your search action  
> @search = Search.find params[:id}  
> #do something with @search

I don’t know why but I continue to get

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.to\_sym

At this point all I’m trying to do is print out one of the values. In  
the  
view I have  
\<%= @search.category\_id %\>

And getting this nil.to\_sym. Not sure what it means .

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 8, 2006, 12:30am UTC](https://www.ruby-forum.com/t/a-bit-lost-could-use-some-direction/71349/5 "2006-10-08T00:30:12Z")

</div>

I’m not entire sure what the problem is, although it sounds to me that  
what you want to do is somthing like

redirect\_to :action =\> :search, :id =\> @search.id

and then in your search action  
@search = Search.find params[:id}  
#do something with @search

That said I’m not sure whether I’m telling you something you already  
know (sorry if I am) or not

Fred

---

<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 8, 2006, 2:37am UTC](https://www.ruby-forum.com/t/a-bit-lost-could-use-some-direction/71349/6 "2006-10-08T02:37:16Z")

</div>

On 10/7/06, s.ross [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> # Assuming the action you really wanted was ‘list’ only filtered …
> 
> list\_setup  
> render :action =\> ‘list’
> 
> BTW: The nil.to\_sym issue is related to @search having a nil value. Add  
> this  
> line to verify that:
> 
> logger.debug “oh, noooo, mr. bill, @search is nil.” unless @search
> 
> Am I on the right track?

Your on a better track then I am , that’s for certain. I’m not entirely  
sure though about the nil.to\_sym error. I found one open ticket on trac  
(  
[dev.rubyonrails.org](http://dev.rubyonrails.org)). Anyway it maybe related to the route I’m  
attempting  
to pass @search to. If I say  
{ redirect\_to searches\_url(@search)} it throws an error but  
{ redirect\_to search\_url(@search)} takes me to show and @search is alive  
there. Anyway I’ll have to hit this again tomorrow and see where your  
ideas  
can lead me. Though I was under the assumption that index and list were  
basically the same.

Stuart

Dark A. wrote:

> > > @search = Search.find params[:id}  
> > > view I have  
> > > –  
> > > View this message in context:  
> > > [http://www.nabble.com/A-bit-lost-%2C-could-use-some-direction-tf2400491.html#a6699570](http://www.nabble.com/A-bit-lost-%2C-could-use-some-direction-tf2400491.html#a6699570)  
> > > Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> >

–

> **[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 8, 2006, 2:45am UTC](https://www.ruby-forum.com/t/a-bit-lost-could-use-some-direction/71349/7 "2006-10-08T02:45:16Z")

</div>

I’m sorry I mixed things up by using ‘list’ when you used ‘index’. Most  
applications use the ‘list’ action to display … um, lists. Many have  
an  
index formed as:

def index  
list  
render :action =\> ‘list’  
end

So, unless your index is more of a splash screen, they may be  
synonymous.

Dark A. wrote:

> > into  
> > something like:
> 
> ideas
> 
> > > > I’m not entire sure what the problem is, although it sounds to me that
> > > 
> > > Stuart
> > 
> > >
> 
> –  
> [Dark ambient - Wikipedia](http://en.wikipedia.org/wiki/Dark_ambient)
> 
> >

–  
View this message in context:  
[http://www.nabble.com/A-bit-lost-%2C-could-use-some-direction-tf2400491.html#a6699642](http://www.nabble.com/A-bit-lost-%2C-could-use-some-direction-tf2400491.html#a6699642)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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 8, 2006, 1:25pm UTC](https://www.ruby-forum.com/t/a-bit-lost-could-use-some-direction/71349/8 "2006-10-08T13:25:56Z")

</div>

On 10/7/06, s.ross [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end
> 
> So, unless your index is more of a splash screen, they may be synonymous.

Doesn’t seem to help, unless I break away from the CRUD create a  
seperate  
method, though I haven’t tried it yet and not sure I want to see that  
goes  
outside of REST.

There is no list in REST controller actions. Not sure how to even  
implement  
it.

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 8, 2006, 2:27am UTC](https://www.ruby-forum.com/t/a-bit-lost-could-use-some-direction/71349/9 "2006-10-08T02:27:15Z")

</div>

Could it be that a redirect is not what you want? Typically, one would  
do  
something like:

def search  
form\_search\_query(params[:search]) # magic code to turn user input  
into  
query

# Assuming the action you really wanted was ‘list’ only filtered …

list  
render :action =\> ‘list’  
end

Now, adding REST into the mix complicates things, but not so much that  
it’s  
unworkable. If you refactor the guts out of your list action, you can do  
something like:

…  
list\_setup  
render :action =\> ‘list’

BTW: The nil.to\_sym issue is related to @search having a nil value. Add  
this  
line to verify that:

logger.debug “oh, noooo, mr. bill, @search is nil.” unless @search

Am I on the right track?

Dark A. wrote:

> > @search = Search.find params[:id}  
> > \<%= @search.category\_id %\>
> 
> And getting this nil.to\_sym. Not sure what it means .
> 
> Stuart
> 
> >

–  
View this message in context:  
[http://www.nabble.com/A-bit-lost-%2C-could-use-some-direction-tf2400491.html#a6699570](http://www.nabble.com/A-bit-lost-%2C-could-use-some-direction-tf2400491.html#a6699570)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).
