更新时间:2023-01-17 08:08:14
使用 build
而不是 new
:
def new
@match = Match.find(params[:match_id])
@score = @match.build_score
end
以下是相关文档:http://guides.rubyonrails.org/association_basics.html#belongs_to-build_association
同理,在create方法中,这样做:
Similarly, in the create method, do it like this:
def create
@match = Match.find(params[:match_id])
@score = @match.create_score(params[:score])
end
相关文档:http://guides.rubyonrails.org/association_basics.html#belongs_to-create_association一个>