i have this
class PagesController < ApplicationController
def index
@textos = Texto.all
@texto_historia = Texto.where(:title => "História").first.contents
@texto_capas_para_sofa = Texto.where(:title => "Capas para Sofá").first.contents
@texto_cortinas = Texto.where(:title => "Cortinas").first.contents
@texto_almofadas = Texto.where(:title => "Almofadas").first.contents
end
The SQL output is:
←[1m←[36mTexto Load (2.0ms)←[0m ←[1mSELECT "textos".* FROM "textos"←[0m
←[1m←[35mTexto Load (1.0ms)←[0m SELECT "textos".* FROM "textos" WHERE ("textos"."title" = 'Hist├│ria') LIMIT 1
←[1m←[36mTexto Load (0.0ms)←[0m ←[1mSELECT "textos".* FROM "textos" WHERE ("textos"."title" = 'Capas para Sof├í') LIMIT 1←[0m
←[1m←[35mTexto Load (1.0ms)←[0m SELECT "textos".* FROM "textos" WHERE ("textos"."title" = 'Cortinas') LIMIT 1
←[1m←[36mTexto Load (1.0ms)←[0m ←[1mSELECT "textos".* FROM "textos" WHERE ("textos"."title" = 'Almofadas') LIMIT 1←[0m
←[1m←[35mTexto Load (0.0ms)←[0m SELECT "textos".* FROM "textos" WHERE ("textos"."title" = 'Informa├º├╡es de Contato') LIMIT 1
What i want is to do just one query for all “textos” model and then search inside an array or anything like that to get the specific variable.
You will need to get the array of all ActiveRecord objects and convert it into a hash storing the data you need.
Then you will be able to access your contents with
@textos["title"].