Trouble with pagaination and conditional statements

i am trying to call this in my controller

if(maincategory == ‘sale’)
@pages, @viewobj = paginate_collection Sale.get_all_sales, :page =>

if(maincategory == ‘job’)
@pages, @viewobj = paginate_collection Job.get_all_jobs, :page =>


but for some reason, when i click on the page link number, i get a nil
error. however, when i just put the
@pages, @viewobj = … outside of the if statement, everything works
fine. i guess the maincategory field gets reset maybe?