Forum: Radiant CMS Extension - multiple checkboxes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
222784b8a601c9e9786cd0291e58fb7a?d=identicon&s=25 Little Known (littleknown)
on 2009-01-22 21:41
Ok, I have two extensions for my first radiant project.

Players
---------
Name
Biography


Sports
---------
Soccer
Football
Baseball
Hockey


In Players--->edit.html.erb

I want to generate a checkbox for each Sport (to assign players to
multiple sports).

I have no idea how to do this, but I have everything else working.
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (seancribbs)
on 2009-01-22 21:55
(Received via mailing list)
Typically I'd do something like this inside the player editing form (in
Haml):

- Sport.all.each do |sport|
  = check_box_tag 'player[sport_ids][]', sport.id,
player.sports.include?(sport), :id => "player_sport_ids_#{sport.id}"
  %label{:for => "player_sport_ids_#{sport.id}"}= sport.name


Sean
222784b8a601c9e9786cd0291e58fb7a?d=identicon&s=25 Little Known (littleknown)
on 2009-01-22 22:38
Sean Cribbs wrote:
> Typically I'd do something like this inside the player editing form (in
> Haml):
>
> - Sport.all.each do |sport|
>   = check_box_tag 'player[sport_ids][]', sport.id,
> player.sports.include?(sport), :id => "player_sport_ids_#{sport.id}"
>   %label{:for => "player_sport_ids_#{sport.id}"}= sport.name
>
>
> Sean

undefined method `sports' for #<Player:

(Sorry, I'm new to rails! )

I would need to add has_and_belongs_to_many :sports to Player.rb model,
right?
222784b8a601c9e9786cd0291e58fb7a?d=identicon&s=25 Little Known (littleknown)
on 2009-01-22 22:50
Sean Cribbs wrote:
> Typically I'd do something like this inside the player editing form (in
> Haml):
>
> - Sport.all.each do |sport|
>   = check_box_tag 'player[sport_ids][]', sport.id,
> player.sports.include?(sport), :id => "player_sport_ids_#{sport.id}"
>   %label{:for => "player_sport_ids_#{sport.id}"}= sport.name
>
>
> Sean

Okay, got all of this figured out and everything looks good in the
views.

I had to create a players_sports table with player_id and sport_id
columns and set has_and_belongs_to_many on player.rb model

The only problem is, it isn't saving to the database on submit. Any tips
for making it work?

If I make an update method in player_controller, (which inherits
abstractmodelcontroller), do i also have to make new, edit, remove, etc?
222784b8a601c9e9786cd0291e58fb7a?d=identicon&s=25 Little Known (littleknown)
on 2009-01-23 17:01
I figured this out, thank you for the initial help.
This topic is locked and can not be replied to.