got a problem with one to one relations
I have some Matches and i want to have one score for a match.
my Match.rb
has_one :score, :dependent
Use build instead of new:
def new
@match = Match.find(params[:match_id])
@score = @match.build_score
end
Here are the docs for this: http://guides.rubyonrails.org/association_basics.html#belongs_to-build_association
Similarly, in the create method, do it like this:
def create
@match = Match.find(params[:match_id])
@score = @match.create_score(params[:score])
end
Docs for this: http://guides.rubyonrails.org/association_basics.html#belongs_to-create_association