我有一个如下的SpecificController,
class SpecificController < ApplicationController
def specific_search # ===== Main =======
self.set_instance_variables
self.set_product_id_sub_category_id
unique_ids = self.get_unique_ids(@product_id,@sub_category_id,["out of stock","permanently discontinued"])
self.set_grid("online",unique_ids)
self.set_grid("local",unique_ids)
end
def include_exclude # ===== Main =======
@type = params[:type].to_s
self.set_product_id_sub_category_id
self.set_sub_category_name(@sub_category_id)
unique_ids = self.get_unique_ids(@product_id,@sub_category_id,["permanently discontinued"])
self.set_grid(@type,unique_ids)
end
def set_instance_variables #===== Sub ====
@cities = Cities.find(:all)
@areas = []
@feature_array = Array.new
@online_grids = Array.new
@local_grids = Array.new
end
def set_product_id_sub_category_id #===== Sub ====
if params[:specific_product_id].present? && params[:sub_category_id].present?
@product_id = params[:specific_product_id].to_i
@sub_category_id = params[:sub_category_id].to_i
end
end
def get_unique_ids(product_id,sub_category_id,exclude_availabilities_array) #===== Sub ====
-
-
-
unique_ids
end
def set_grid(grid_type,unique_ids) #===== Sub ====
if grid_type == "online"
@online_grids = OnlineGridDetails.get_grid(unique_ids)
elsif grid_type == "local"
@local_grids = LocalGridDetails.get_grid(unique_ids)
end
end
end
在上面的类中,标记为“主要”的方法是我正在使用的方法。其他标记为“Sub”的方法都由使用“self.”的主方法调用。这是一个好习惯吗?如果不是,那些“Sub”方法属于哪里?