在rails上升级代码ruby

时间:2013-11-12 13:12:47

标签: ruby-on-rails ruby

我的控制器中有价值

@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

2 个答案:

答案 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])