1

スキャフォールディングは、Create/Update メソッドを持つコントローラーを作成します。これらのメソッドには、HTML と JSON のレンダリングがあります。HTML は知っていますが、JSON が何であるかはわかりません。そこに JSON を含める必要がありますか?それとも、それを取り出しても HTML レンダリングで作業できますか?

話しているコードは次のとおりです。

def create
  @judge = Judge.new(judge_params)

  respond_to do |format|
    if @judge.save
      format.html { redirect_to @judge, notice: 'Judge was successfully created.' }
      format.json { render action: 'show', status: :created, location: @judge }
    else
      format.html { render action: 'new' }
      format.json { render json: @judge.errors, status: :unprocessable_entity }
    end
  end
end
4

2 に答える 2

1

JSON について気にしない場合は、次のように簡単に実行できます。

def create
  @judge = Judge.new(judge_params)

  if @judge.save
    redirect_to @judge, notice: 'Judge was successfully created.'
  else
    render action: 'new'
  end
end
于 2013-08-16T15:23:34.977 に答える