0

編集後に新しい選択ボックスが表示されます。編集で変更したモデルは、fields_for オプションを使用した別のモデルです。

コントローラーの new および create アクションに問題があると誰かが言いました。

現在のコントローラー:

def new
  @print = Print.new
end

def create
  @print = Print.new(params[:print])
  @print.user_id = current_user.id
  if @print.save
    redirect_to print_path(@print), :flash => { :success => "Successfully created your Print Order." }
  else
    render :action => 'new'
  end
end

def edit
  @print = Print.find(params[:id])
  @print.blackwhites.build
end

モデルからのデータを編集する fields_for :

  def index

  def new
    @blackwhite = Blackwhite.new
  end

  def create
    @blackwhite = Blackwhite.new(params[:blackwhite])
    @blackwhite.print_id = @print.id
  end

  def update
    @blackwhite = Blackwhite.find(params[:id])
  end

  def show
    @blackwhite = Blackwhite.find(params[:id])
  end

  def edit
    @blackwhite = Blackwhite.find(params[:id])
  end

編集:

問題を修正しました。

4

1 に答える 1

1

私が最初に目にするもの:

def create
  @blackwhite = Blackwhite.new(params[:blackwhite])
  @blackwhite.print_id = @print.id
  render :action => 'new'   <<<< ?????
end

試す

redirect_to print_path(@print)

これは、作成されたばかりのデータを表示する、またはネストされたケースでは、作成されたばかりのレコードの親を表示する、典型的なデフォルトのことです。本当に必要なのは、作成後に新しいアクションのレンダリングを停止することだけです。それは正しくありません!

于 2013-06-12T18:00:32.333 に答える