I have a SpecificController as below,
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
In the above class, the methods that are marked as “Main” are the ones that Im using.
Other methods marked as “Sub” are all called by the main methods using “self.”.
Is this a good practice?
If not, where do those “Sub” methods belong?
If it helps you navigate and read your code, then whatevs, man.
I personally put all auxilliary methods to
privatesection of the class at the bottom of file.