1

updateアクションでは次のように動作しますnested_formが、createこのエラーが発生します。

Couldn't find Student with ID=12 for Cv with ID=


コントローラ:

def new
  @cv = Cv.new
  @cv.student = current_student
end

def create
  @cv = Cv.new(params[:cv])

  if @cv.save
    redirect_to student_dashboard_path,
      notice: t('activerecord.successful.messages.created', model: @cv.class.model_name.human)
  else
    render 'new'
  end
end


モデル:

class Cv < ActiveRecord::Base
  attr_accessible :student_attributes

  belongs_to :student
  accepts_nested_attributes_for :student
end


意見:

= f.simple_fields_for :student do |s|
  = s.input :english_level, collection: [['Low', 1], ['High', 2]]
4

1 に答える 1

1

route.rb も変更する必要があります。

resources :parent do
  resources :child
end

Jose Valim によるこの便利な実装 - inherited-resourcesを見てください。

于 2012-11-17T14:48:33.223 に答える