how to store an array from a multiple select

2019-09-06 21:18发布

i am currently using this select = select(:schedule, :selected_players, @players.map { |p| [full_name(p), p.id] }, {:include_blank => 'None'}, "data-placeholder" => 'Add Players to Lineup', :prompt => 'Add Players to Lineup', :multiple => "multiple")

and would like to store the information into an array within the database, then access this array for different pars of the site

there is a copy of things im needing to know

  1. how best to store into the database, current this field value is binary
  2. how to then extract each value from the array

thanks

1条回答
姐就是有狂的资本
2楼-- · 2019-09-06 21:49

Sounds like you want serialize.

If you make the selected_players column a text column and mark your Schedule model with

serialize :selected_players

Then you can save a Ruby array into the attribute. It'll be written to the database in YAML, and pop out exactly as it went in, as an array, when you read it.

查看更多
登录 后发表回答