Domanda

@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.

È stato utile?

Soluzione

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

@trainer.sportists.each { |sportist| sportist.name = sportist.name.humanize }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top