1

On the update action the following nested_form works, but on create I get this error:

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


Controller:

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


Model:

class Cv < ActiveRecord::Base
  attr_accessible :student_attributes

  belongs_to :student
  accepts_nested_attributes_for :student
end


View:

= f.simple_fields_for :student do |s|
  = s.input :english_level, collection: [['Low', 1], ['High', 2]]
doesterr
  • 3,955
  • 19
  • 26
tomekfranek
  • 6,852
  • 8
  • 45
  • 80

1 Answers1

1

You should make changes to your route.rb too.

resources :parent do
  resources :child
end

Take a look at this useful implementation by Jose Valim - inherited-resources .

R Milushev
  • 4,295
  • 3
  • 27
  • 35
  • I can see in your controller , there are missing parts , building associates between resources . You can reference here in [this discusion]:http://stackoverflow.com/questions/5207038/the-better-way-to-pass-the-foreign-key-value-to-the-rails-controller . – R Milushev Nov 17 '12 at 14:54