Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-26-2006, 11:07 PM   #1
Registered: Oct 2001
Location: Washington, DC
Distribution: Debian, Archlinux, Ubuntu, Sidux
Posts: 244

Rep: Reputation: 30
Can you help me with search in Ruby on Rails?

I'm trying to create a way to search in my Ruby on Rails program. I am using the TextSearch plugin which seems to be working ok. The problem I am having is passing the info from the view to the controller.

My controller, again based on TextSearch, is simply:

 def search
        @results = query
My view is a bit more complicated:

  <div class="search"  <%= form_tag :action =>'search', :controller => 'post' %>

<td width="50" <%= text_field 'product','@query' %>
<td width="100"><%= submit_tag "Search" %>
<%= end_form_tag %>

<% for column in Product.content_columns %>
 <th><%= column.human_name %></th>
<% end %>

<% for product in @results %>
    <% for column in Product.content_columns %>
    <td><%=h product.send( %></td>
    <% end %>
Any help would be greatly appreciated. Search is supposed to be pretty easy but somehow I can't quite get it..
Old 01-05-2007, 07:25 PM   #2
LQ Newbie
Registered: Jan 2007
Posts: 6

Rep: Reputation: 0
In your controller, you call query, but query isn't defined anywhere. What you probably want is params['query'].

So, in your controller, first do

@query = params['query']
before you do

@results = @query # Note the @query instead of query, because I assigned params['query'] to @query instead of to query
Then, in your view, you can use:

<td width="50" <%= text_field_tag 'query', @query %>
<td width="100"><%= submit_tag "Search" %>
Note, that you quoted @query in your view, which means that you get the literal value '@query' instead of the value of the @query instance variable. Also you didn't assign anything to the @query instance variable in your controller. (The instance variables in your controller are inherited by the views.)

Lastly, there don't seem to be many Rails coders on this forum (I've only just registered myself and I'm not a habitual reader), so next time asking your question on the excellent "Ruby on Rails: Talk" Google group may give you an answer sooner.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Ruby on Rails Ramps Up LXer Syndicated Linux News 0 03-30-2006 04:21 AM
LXer: Ruby on Rails LXer Syndicated Linux News 0 02-16-2006 05:16 PM
LXer: Ruby on Rails on Debian LXer Syndicated Linux News 0 01-09-2006 08:01 PM
LXer: Ruby off the Rails LXer Syndicated Linux News 0 12-24-2005 05:31 PM
Ruby on Rails pache config gherikill Linux - Software 1 10-11-2005 11:02 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:17 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration