如何从多选中存储数组 [英] how to store an array from a multiple select

查看:70
本文介绍了如何从多选中存储数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用select = select(:schedule,:selected_players,@ players.map {| p | [full_name(p),p.id]},{:include_blank => 'none'}, data-placeholder =>'将玩家添加到阵容中,:prompt =>'将玩家添加到阵容中,:multiple =>多个)

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

我需要知道一些事情


  1. 如何最好地存储到数据库中,当前此字段值为二进制

  2. 如何从数组中提取每个值

谢谢

推荐答案

您想要的声音 序列化

Sounds like you want serialize.

如果您使 selected_players 列为文本列并标记您的<$ c带有

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

serialize :selected_players

然后,您可以将Ruby数组保存到属性中。它将以YAML写入数据库,并在读取时以数组形式完全弹出。

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.

这篇关于如何从多选中存储数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆