【发布时间】:2016-10-06 15:12:20
【问题描述】:
我有一个关于将值存储到整数变量中的问题。是否可以将不同的 id 存储到同一个变量中? 这是我的问题,我想使用 collection_select 来保存许多 id。 我的代码实际上适用于一个变量,如下所示:
我的代码:
用户模型:
has_many :pins
scope :artist, -> { where(artist: true) }
引脚型号:
belongs_to :user
引脚控制器:
def new
@pin = Pin.new
@users = User.all.artist
end
def create
@pin = current_user.pins.build(pin_params)
if @pin.save
redirect_to @pin, notice: "successfully created!"
else
render 'new'
end
end
固定/新(视图):
<div class="form-group">
<%= f.collection_select(:pin_maker, @users, :id, :pseudo) %>
</div>
我想为我的新观点提供类似的东西:
<div class="form-group">
<%= f.collection_select(:pin_maker, @users, :id, :pseudo, { }, {:multiple => true}) %>
</div>
但是变量没有保存在我的 sql 表中。 所以我的问题是:有可能将许多 id 存储在同一个整数变量 (:pin_maker) 中吗?或者我应该为此创建一个新表吗?
【问题讨论】:
-
That's possible to store many id in the same variable (:pin_maker) which is an integer ?=> 没有
标签: mysql sql ruby-on-rails ruby