LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 04-26-2006, 11:07 PM   #1
viniosity
Member
 
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:

Code:
 def search
        @results = Product.search query
 end
My view is a bit more complicated:

Code:
<table>
  <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 %>
  </div>
</table>

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

<% for product in @results %>
   <tr>
    <% for column in Product.content_columns %>
    <td><%=h product.send(column.name) %></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
bigsmoke
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

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

Code:
@results = Product.search @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:

Code:
<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.
 
  


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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