我的控制器中有价值
@tour = Tour.find(:first,
:conditions => ["beginDate in (?) AND tour LIKE ? AND duration + 1 = ? OR
beginDate in (?) AND tour LIKE ? AND duration + 1 = ?",
@day.day, @day.travel.tour.name, @day.cruise.tour_days_count,
@day.day, 'Some Name', @day.cruise.tour_days_count])
他工作正常。如何升级此代码,让他更紧凑?
ruby 1.8.7,rails 2.3
答案 0 :(得分:0)
@tour = Tour.where("beginDate in (?) AND tour IN (?) AND (duration + 1) = ?",
@day.day, [@day.travel.tour.name, 'Some Name'], @day.cruise.tour_days_count])
.first
答案 1 :(得分:0)
@tour = Tour.find(:first, :conditions => ["beginDate in (?) AND tour IN (?) AND (duration + 1) = ?",
@day.day, [@day.travel.tour.name, 'Some Name'], @day.cruise.tour_days_count])