2015-03-03 79 views
0

如何使用rails 4新語法重寫下面的代碼。rails 4語法修改

Tracker.find(:all, :joins => :projects, 
         :select => "DISTINCT #{Tracker.table_name}.*", 
         :conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> #{STATUS_ARCHIVED}", lft, rgt], 
         :order => "#{Tracker.table_name}.position") 
+0

你可以用'where'。 – 2015-03-03 11:03:33

回答

1

下面是等價的方式:

Tracker.joins(:projects) 
     .where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> #{STATUS_ARCHIVED}", lft, rgt) 
     .select("DISTINCT #{Tracker.table_name}.*") 
     .order("#{Tracker.table_name}.position") 
+0

完美!感謝代碼。我將練習這種新的語法! – Packer 2015-03-03 11:06:22