I am trying to use two if statements within my index. The first allows the user to view by tags, and the second defines the Kaminari pagination gem, gem 'kaminari'
.
The problem is, I can't get both to work. With the code as is below, the pagination works, but filtering by tag does not. If I comment out the pagination, the the tags work.
I'm fairly sure I don't have the correct logic around the two if statements, but I can't work out how to right this.
class CoffeeshopsController < ApplicationController
def index
if params[:tag]
@coffeeshops = Coffeeshop.tagged_with(params[:tag])
else
@coffeeshops = Coffeeshop.all.order("created_at DESC").page params[:page]
end
if params[:term]
@coffeeshops = Coffeeshop.search_by_full_name(params[:term])
else
@coffeeshops = Coffeeshop.all.order("created_at DESC").page params[:page]
end
end