0
我的控制器中有以下代码。实例varibale与控制器中的方法调用
def index
@customer = Customer.find(params[:customer_id])
@current_orders = @customer.current_orders
@pending_orders = @customer.pending_orders
@previous_orders = @customer.previous_orders
@recurring_orders = @customer.recurring_orders
end
正如你看到的,所有的实例变量(@ current_orders,@ pending_orders等),可以从@customer获得。
写这段代码的最好方法是什么? 我是否需要在控制器中创建这些实例变量,或者我只是通过视图中的@customer变量使用这些变量。
感谢