Displaying 3 results from an estimated 3 matches for "find_all_by_title".
2006 Jun 12
5
Doing a simple search from the database?
...a search form. I have half my app done (I can write all the
info I want to my database), but pulling the data out dynamically is
giving me trouble.
I have both the "ruby for rails" book and the Agile Development book.
They both give great info on static queries. Such as:
post = Posts.find_all_by_title("green")
But I need to be able to pull the record dynamically. For instance, a
form where I can type in "green" and search the "title" and "body"
columns in the "posts" table.
It seems like a simple enough query but I''m having trouble f...
2006 Jun 13
9
Find DB items by "title"
...;<br/>
<input type=text name="title">
<input type="submit" value="Search »" class="primary" />
<%= end_form_tag %>
That points to this action in my "post_controller.rb"
def search
@post = Post.find_all_by_title(params[:title])
end
Which I think is assigning the @post variable with the results. But how
exactly can I get them to display? I made a dummy action in the
post_contoller.rb called "show_search" and a view called
"show_search.rhtml" what''s the last step to get the r...
2006 Jun 14
1
Partial matches with find_by
I have a form passing a parameter to a "show_search" action. Everything
goes fine, as long as i search for the exact title of the post. How do I
do a partial or "wild card" search? Code below:
def show_search
@posts = Post.find_all_by_title(params[:title])
end
--
Posted via http://www.ruby-forum.com/.