问题
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
- how best to store into the database, current this field value is binary
- how to then extract each value from the array
thanks
回答1:
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.
来源:https://stackoverflow.com/questions/11934786/how-to-store-an-array-from-a-multiple-select