how to store an array from a multiple select

我怕爱的太早我们不能终老 提交于 2019-12-13 05:54:37

问题


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:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!