# Filtering main 'list' page

**URL:** <https://www.ruby-forum.com/t/filtering-main-list-page/109143>\
**Category:** Rails\
**Created:** [July 11, 2007, 8:53pm UTC](https://www.ruby-forum.com/t/filtering-main-list-page/109143 "2007-07-11T20:53:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 11, 2007, 8:53pm UTC](https://www.ruby-forum.com/t/filtering-main-list-page/109143/1 "2007-07-11T20:53:18Z")

</div>

Alright…I’m stuck again. I’d appreciate any help.

I’m trying to ‘filter’ what is on my main page. I’m using Apache LDAP  
authentication and not the ror one…so my username is passed through  
using a variable.

I’m trying to filter the ‘division\_id’ to a certain number…  
basically, I want to do…

select \* from responses WHERE division\_id = ‘1’;

I’ve tried to add stuff to the index and the list areas of the  
controller, but it seems like I can’t get it to filter out records  
that should not be displayed for that username. In the SQL query, it  
looks correct in the development.log file…but it just doesn’t  
display correctly.

Thank you for any help!

mike

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 11, 2007, 10:02pm UTC](https://www.ruby-forum.com/t/filtering-main-list-page/109143/2 "2007-07-11T22:02:26Z")

</div>

removed\_email\_address@domain.invalid wrote:

> 

@responses = Response.find(:all, :conditions =\> [‘division\_id =  
?’,@division\_id])

Have read AWDWR yet? Highly recommended!  
[http://www.pragmaticprogrammer.com/titles/rails/](http://www.pragmaticprogrammer.com/titles/rails/)

–  
[http://www.5valleys.com/](http://www.5valleys.com/)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 11, 2007, 10:19pm UTC](https://www.ruby-forum.com/t/filtering-main-list-page/109143/3 "2007-07-11T22:19:28Z")

</div>

Thanks for the info. Yeah, I’ve gone through AWDWR but still run into  
problems every now and then. I _finally_ just got it working. Here  
is what’s in my controller…

def list  
@Division = %x("#{RAILS\_ROOT}/ProtectedFiles/bin/adlookup2.pl"  
#{ENV[‘Username’]})  
@responses = Response.find(:all, :conditions =\> [“division\_id  
= ?”, @Division])

```
# @response_pages, @responses = paginate :responses, :per_page =>

```

10  
end

It turns out that if I uncomment that @response\_pages line, for  
whatever reason, it throughs everything off and does not run my  
conditions filter. But then, if I add the :conditions to that line  
and comment out my query, everything works fine.

I suppose that’s where I was getting stuck up at. So now, here is my  
final line where everything works great…

def list  
@Division = %x("#{RAILS\_ROOT}/ProtectedFiles/bin/adlookup2.pl"  
#{ENV[‘Username’]})

```
@response_pages, @responses = paginate :responses, :per_page =>

```

10, :conditions =\> [“division\_id = ?”, @Division]  
end

Thank you for your help!!!

Mike

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 12, 2007, 12:16am UTC](https://www.ruby-forum.com/t/filtering-main-list-page/109143/4 "2007-07-12T00:16:54Z")

</div>

you can’t paginate an already retrieved data set using the built in  
rails pagination helpers. You need to put your conditions into the  
‘paginate’ method call, which it looks like you did the second time  
around. You might also want to look into using another paginator as  
the built in pagination has been deprecated - the “will\_paginate”  
plugin is a good alternative.

Mike
