親モデルのidを手打ちで子モデルに引き継いでいるのですが、親モデルからidを継承しつつ手入力なしで子モデルに移動したいです。
親モデル:order_list
子モデル:return_list
関連するコントローラー
order_list_controller.rb
Ruby
1def create 2 @order_list = OrderList.new(order_list_params) 3 4 respond_to do |format| 5 if @order_list.save 6 format.html { redirect_to return_ref_return_lists_url, notice: 'Order list was successfully created.' } 7 format.json { render :show, status: :created, location: @order_list } 8 else 9 format.html { render :new } 10 format.json { render json: @order_list.errors, status: :unprocessable_entity } 11 end 12 end 13 end
return_list_controller.rb
RUBY
1def return_ref 2 3 @return_list = ReturnList.new 4 @return_list["order_list_id"] = ここにidを入れたい 5 6 respond_to do |format| 7 if @return_list.save 8 format.html { redirect_to edit_return_list_path(@return_list), notice: 'Return list was successfully created.' } 9 format.json { render :show, status: :created, location: @return_list } 10 else 11 format.html { render :new } 12 format.json { render json: @return_list.errors, status: :unprocessable_entity } 13 end 14 end
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。