控制器在NoMethodError創建具有的has_many關聯結果的對象
class ExperiencesController < ApplicationController
def create
@resume = Resume.find(params[:resume])
@experience = @resume.build_experience(params[:experience])
end
end
class ResumesController < ApplicationController
def create
@resume = Resume.new(params[:resume])
@resume.build_webconnection
@resume.build_experience # <<<<<<<<< Error occurs here
if @resume.save
#UserMailer.created_resume_email(@user).deliver
redirect_to @resume
else
@title = "Create a new resume"
render :action => "new"
end
end
end
模型時,我嘗試創建簡歷(其還創建了恢復相關聯的經驗)
class Experience < ActiveRecord::Base
belongs_to :resume
end
class Resume < ActiveRecord::Base
has_one :webconnection
has_many :experiences
end
錯誤消息
NoMethodError in ResumesController#create
undefined method `build_experience' for #<Resume:0xbb428a4>
我覺得我有一切都很到位,但錯過了's'或某個地方。任何想法,爲什麼我得到這個錯誤?