非常感谢这里的任何见解。
从 rails 中的 form_for 内部,我将多个选择值插入到数据库中,如下所示:
<div class="new-partner-form">
<%= form_for [:admin, matching_profile.partner, matching_profile], :html => {:id => "edit_profile", :multipart => true} do |f| %>
<%= f.submit "Submit", :class => "hidden" %>
<div class="rounded-block quarter-wide radio-group">
<h4>Exclude customers from source:</h4>
<%= f.select :source, User.select(:source).group(:source).order(:source).map {|u| [u.source,u.source]}, {:include_blank => false}, {:multiple => true} %>
<%= f.error_message_on :source %>
</div>
然后我试图从数据库中提取值,如下所示:
def does_not_contain_source(matching_profiles)
Expression.select(matching_profiles, :source) do |keyword|
Rails.logger.info("Keyword is : " + keyword)
@customer_source_tokenizer ||= Tokenizer.new(User.select(:source).where("id = ?", self.owner_id).map {|u| u.source}[0]) #User.select("source").where("id = ?", self.owner_id).to_s)
@customer_source_tokenizer.divergent?(keyword)
end
end
但得到这个:
ExpressionErrors: Bad syntax: ---
- ""
- B
- ""
这就是数据库中的值,但是当我以这种方式访问它时,它似乎窒息了。这样做的正确方法是什么?
让我这样问。用户从多项选择中的选择以这种方式插入到 db 字段中:
---
- ""
- B
- "
有没有更好、更有用的方法可以将选择的内容存储到数据库中?