我想要一個更好的建議...更好地使用ruby特性。任何人都可以給我一個更好的解決方案來組裝這個查詢?Ruby在WHERE子句中使用帶有多個選項的查詢
@conditions = ""
if(ratings["G"] == "1")
@conditions += " 'G' "
end
if(ratings["PG"] == "1")
@conditions += " OR rating = 'PG' "
end
if(ratings["PG-13"] == "1")
@conditions += " OR rating = 'PG-13' "
end
if(ratings["R"] == "1")
@conditions += " OR rating = 'R' "
end
@movies = Movie.where("rating = "+ @conditions)
return @movies
太感謝你了,
如果可能,請詳細說明如何使用.keys。謝謝! – 2012-03-10 15:57:02