Question

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?

Was it helpful?

Solution

this helped. In my matching_profiles model:

serialize :excluded_sources
serialize :included_sources
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top