I am writing a loop with switch case , instead of querying database three time , I am getting all lookup in one query and looping with conditions to assign to different instance variable ( which I will use in simple form as collections) . I am not sure how to append active record relations to instance variable, pls help me.
class QuestionsController < ApplicationController
def index
@question = Question.new
@question_lookups = Lookup.where({:look_up_for => "question"})
@question_lookups.each do |lk|
case lk.look_up_type
when 'mode'
@question_mode = lk #How can i do this here..?
when 'status'
@question_status = lk
else
@question_type = lk
end
end
session[:lk] = @question_mode
# @question_mode = Lookup.where({:look_up_for => "question", :look_up_type => "mode"})
# @question_status = Lookup.where({:look_up_for => "question", :look_up_type => "status"})
# @question_type = Lookup.where({:look_up_for => "question", :look_up_type => "type"})
end
end
Convert question_mode and so on into arrays and push lk to it