Filtering main 'list' page

1 view
Skip to first unread message

Jul 11, 2007, 2:52:51 PM7/11/07
to Ruby on Rails: Talk
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 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!


Jon Garvin

Jul 11, 2007, 4:01:24 PM7/11/07
@responses = Response.find(:all, :conditions => ['division_id =

Have read AWDWR yet? Highly recommended!


Jul 11, 2007, 4:18:39 PM7/11/07
to Ruby on Rails: Talk
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/"

@responses = Response.find(:all, :conditions => ["division_id

= ?", @Division])

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

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/"

@response_pages, @responses = paginate :responses, :per_page =>
10, :conditions => ["division_id = ?", @Division]

Thank you for your help!!!


Mike Garey

Jul 11, 2007, 6:16:21 PM7/11/07
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.


Reply all
Reply to author
0 new messages