在 Rails 3 中从数据库中选择多个选择值时出现问题
非常感谢这里的任何见解。
从 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
- ""
这就是数据库中的值但当我以这种方式访问它时,它似乎感到窒息。这样做的正确方法是什么?
让我这样问吧。用户从多重选择中进行的选择以这种方式插入到数据库字段中:
---
- ""
- B
- "
是否有更好、更有用的方法可以将选择的内容存储到数据库中?
ANY insight here is greatly appreciated.
From inside of a form_for in rails, I'm inserting multiple select values into the database, like this:
<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>
I'm then trying to pull the value from the database like this:
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
but getting this:
ExpressionErrors: Bad syntax: ---
- ""
- B
- ""
this is what the value is in the database but it seems to choke when i access it this way. What's the right way to do this?
let me ask it this way. The user's selection from the multiple select is being inserted into the db field this way:
---
- ""
- B
- "
is there a better, more useful way I can store what's been selected into the DB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有帮助。在我的matching_profiles模型中:
this helped. In my matching_profiles model: