我们需要在新方法中创建关联对象吗?

时间:2017-05-03 13:56:03

标签: ruby-on-rails

查看spree

中的以下代码
  def new
    @stock_movement = stock_location.stock_movements.build
  end

  def create
    @stock_movement = stock_location.stock_movements.build(stock_movement_params)
    @stock_movement.save
    flash[:success] = flash_message_for(@stock_movement, :successfully_created)
    redirect_to admin_stock_location_stock_movements_path(stock_location)
  end

是否真的有必要在new方法

中构建关联对象
@stock_movement = stock_location.stock_movements.build

或以下行很好

@stock_movement = StockMovement.new

请解释..

0 个答案:

没有答案