Filtering main 'list' page

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

[email protected] wrote:

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

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


http://www.5valleys.com/

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

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