# Building a Search Page as part of CRUD

**URL:** <https://www.ruby-forum.com/t/building-a-search-page-as-part-of-crud/100400>\
**Category:** Rails\
**Created:** [July 28, 2006, 7:10pm UTC](https://www.ruby-forum.com/t/building-a-search-page-as-part-of-crud/100400 "2006-07-28T19:10:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Stark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@Dan\_Stark](https://www.ruby-forum.com/u/Dan_Stark)\
**Post date:** [July 28, 2006, 7:10pm UTC](https://www.ruby-forum.com/t/building-a-search-page-as-part-of-crud/100400/1 "2006-07-28T19:10:41Z")

</div>

I’ve been experimenting with Rails over the past couple of days and  
have come across something that seems harder than it should be. In  
previous frameworks I have used (WebObjects, php) a full search page  
(which leads into a list view populated with search results) was part  
of the CRUD that was either dynamically or statically created after  
specifying table/object schema. In WebObjects this was a very cool  
feature of DTW (direct to web), in php I rolled my own crud generator  
with searching capabilities even though I’m sure plenty exist already.

I’ve looked through the archives and google and have found mentions  
of the lack of a search page in Rails, but as yet no solutions. I’m  
wondering if there are any plugins or scaffolding enhancements that  
add a search page to the basic CRUD interface. I’m not looking for a  
full text search just an interface that provides a form containing  
all table fields that, once submitted, builds a database query and  
returns the results.

TIA,  
Dan

---

<div class="post-metadata">

**Author:** ![Dan\_Stark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@Dan\_Stark](https://www.ruby-forum.com/u/Dan_Stark)\
**Post date:** [August 7, 2006, 11:24am UTC](https://www.ruby-forum.com/t/building-a-search-page-as-part-of-crud/100400/2 "2006-08-07T11:24:14Z")

</div>

I’m also looking for a search scaffold plugin… anybody?

---

<div class="post-metadata">

**Author:** ![Dan\_Stark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@Dan\_Stark](https://www.ruby-forum.com/u/Dan_Stark)\
**Post date:** [August 7, 2006, 11:30am UTC](https://www.ruby-forum.com/t/building-a-search-page-as-part-of-crud/100400/3 "2006-08-07T11:30:16Z")

</div>

Shimon A. wrote:

> I’m also looking for a search scaffold plugin… anybody?

…and I was thinking of exactly this a while back… and was going to  
post to the list asking about it at night… 😃  
Thanks for asking for me…  
Cheers  
Mohit.

---

<div class="post-metadata">

**Author:** ![Dan\_Stark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@Dan\_Stark](https://www.ruby-forum.com/u/Dan_Stark)\
**Post date:** [August 7, 2006, 11:36am UTC](https://www.ruby-forum.com/t/building-a-search-page-as-part-of-crud/100400/4 "2006-08-07T11:36:17Z")

</div>

The “Rails Recipes” book has something that could help… a generic  
model  
search…from there to a plugin it should be a short way…

2006/8/7, Mohit S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Michael S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

[www.stellar-legends.de](http://www.stellar-legends.de) - Weltraum-Browsergame im Alpha-Stadium

---

<div class="post-metadata">

**Author:** ![Dan\_Stark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@Dan\_Stark](https://www.ruby-forum.com/u/Dan_Stark)\
**Post date:** [August 7, 2006, 3:49pm UTC](https://www.ruby-forum.com/t/building-a-search-page-as-part-of-crud/100400/5 "2006-08-07T15:49:23Z")

</div>

Mohit S. wrote:

> Thanks Michael,
> 
> Actually, that was the reason I had scheduled to ask at night… cos I  
> planned to take a look at the Recipes book before posting my question…  
> I think AWDWR2 does not really go into this aspect in much detail…
> 
> Cheers  
> Mohit.

this may be completely off, but here is an article on creating a live  
search with sortable table columns and pagination:

[http://dev.nozav.org/rails\_ajax\_table.html](http://dev.nozav.org/rails_ajax_table.html)

i’ve used it in a few smaller projects and the search part might be of  
some use.

---

<div class="post-metadata">

**Author:** ![Dan\_Stark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@Dan\_Stark](https://www.ruby-forum.com/u/Dan_Stark)\
**Post date:** [August 7, 2006, 11:39am UTC](https://www.ruby-forum.com/t/building-a-search-page-as-part-of-crud/100400/6 "2006-08-07T11:39:17Z")

</div>

Thanks Michael,

Actually, that was the reason I had scheduled to ask at night… cos I  
planned to take a look at the Recipes book before posting my question…  
I think AWDWR2 does not really go into this aspect in much detail…

Cheers  
Mohit.

---

<div class="post-metadata">

**Author:** ![Dan\_Stark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@Dan\_Stark](https://www.ruby-forum.com/u/Dan_Stark)\
**Post date:** [August 8, 2006, 2:47pm UTC](https://www.ruby-forum.com/t/building-a-search-page-as-part-of-crud/100400/7 "2006-08-08T14:47:44Z")

</div>

heri rakotomalala wrote:

> well, for me, this takes two lines of code  
> def search  
> @items\_pages, @items = paginate ‘Item’, :conditions =\> [‘name LIKE ?’,  
> params[:search\_text]], :per\_page =\> 10  
> render :action =\> :list  
> end

Isn’t that vulnerable to SQL Injection attacks?

---

<div class="post-metadata">

**Author:** ![Dan\_Stark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@Dan\_Stark](https://www.ruby-forum.com/u/Dan_Stark)\
**Post date:** [August 7, 2006, 11:58pm UTC](https://www.ruby-forum.com/t/building-a-search-page-as-part-of-crud/100400/8 "2006-08-07T23:58:24Z")

</div>

well, for me, this takes two lines of code

def search  
@items\_pages, @items = paginate ‘Item’, :conditions =\> [‘name LIKE ?’,  
params[:search\_text]], :per\_page =\> 10  
render :action =\> :list  
end

so you reuse the list view

* * *

Heri  
[http://sprinj.com](http://sprinj.com)

---

<div class="post-metadata">

**Author:** ![Dan\_Stark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@Dan\_Stark](https://www.ruby-forum.com/u/Dan_Stark)\
**Post date:** [August 8, 2006, 2:47pm UTC](https://www.ruby-forum.com/t/building-a-search-page-as-part-of-crud/100400/9 "2006-08-08T14:47:45Z")

</div>

Nope – the placeholder will be safely replaced by whatever string there  
is  
in params[:search\_text]
