문제

@trainer = Trainer.new(trainer_params)
@trainer.name = @trainer.name.humanize
@trainer.surname = @trainer.surname.humanize

This bit works fine, but I would also like to apply the same thing to Sportist which belongs_to :trainer and

@trainer.sportists.name = @trainer.sportists.name.humanize

doesn't work, so how would I go about doing it? Note that this is a nested form.

도움이 되었습니까?

해결책

If @trainer.sportists is a collection (an has_many relation ?), try this:

@trainer.sportists.each { |sportist| sportist.name = sportist.name.humanize }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top