class PageController < ApplicationController # caches_page :home, :informativo def home @informativos = Informativo.order("Datainc desc").page(params[:page] || 1) end def informativo @informativo = Informativo.find(params[:id]) @title = @informativo.titulo end def tag @tag = Tag.find_by(param: params[:param]) @informativos = @tag.informativos.page(params[:page] || 1) @title = @tag.nome render "list" end def tema @tema = Tema.find_by(param: params[:param]) @informativos = @tema.informativos.page(params[:page] || 1) @title = @tema.padrao render "list" end def busca @search = params[:q] terms = @search.to_s.split(/\s+/) scope = Informativo.all terms.each do |term| clean = term.gsub(/[+\-*"()~<>]/, "") next if clean.blank? scope = scope.where("titulo LIKE ?", "%#{clean}%") end @informativos = scope.order("Datainc desc").page(params[:page] || 1) @title = "Busca: #{@search}" render "list" end end