i've in a rails form a multiple checkbox values. I need to pass this values (if checked) to a model that create the categories.
I've this in form.html_erb
<%= form.check_box :categories, {multiple: true}, "U6", nil %>
<%= form.check_box :categories, {multiple: true}, "U8", nil %>
<%= form.check_box :categories, {multiple: true}, "U10", nil %>
I want to create TeamCategory with the values checked. Something like this?
def create_tournament_team_categories
VALUE_CHECKED.each do |name|
team_category = TeamCategory.where(name: VALUE_CHECKED).first_or_create
self.tournament_team_categories << TournamentTeamCategory.create(team_category: team_category)
end
end
Aucun commentaire:
Enregistrer un commentaire