I am building a sample e-commerce app using ruby on rails.One of my controller name is "products_controller".This controller is also placed inside as a nested controller.The actions inside these controllers are same.How can we represent these actions without duplication of codes. The code samples are given below.
app/controllers/products_controller.rb
def index
@product = Product.all
@vari = @products.variants
.............
.............
end
app/controllers/master_admins/products_controller.rb
def index
@product = Product.all
@vari = @products.variants
.............
.............
end
app/controllers/master_admins/properties_controller.rb
def product
@product = Product.all
@vari = @products.variants
.............
.............
end
The above actions contains the same set of codes.How can we refactor this so that the code doesnt get repeated.
Thanks in advance....