ruby - Rails ActiveRecord trigger query for each parameter passed? -
how can trigger different rails activerecord query each time parameter sent controller?
if params[:sort].present? sort_input = ['foundation', 'originality', 'dynamics', 'execution', 'battle', 'votes'] @foundation = if sort_input[0].include? #here model.order...activerecord query end @originality = if sort_input[1].include? end @dynamics = if sort_input[2].include? end @execution = if sort_input[3].include? end @battle = if sort_input[4].include? end @votes = if sort_input[5].include? end
use case statement
case params[:sort] when 'foundation' @foundation = # query goes here when 'originality' @originality = # different query goes here .. else # else case end
Comments
Post a Comment