Reputation: 730
I want to check if a campaign has the correct brand and if the campaign is active (valid_until is a Date-Record). The entry inside the record should only appear if both conditions are true.
I'm trying to get this to work:
<% Brand.all.each do |b| %>
<%= f.collection_select(:campaign, Campaign.where(brand: b.company).where(:valid_until < Date.now), :campaign, :campaign, {prompt:true}, {class: 'form-control'}) %>
<% end %>
I'm getting these errors:
syntax error, unexpected tCONSTANT, expecting ')' ...ompany).where(:valid_until Date.now), :campaign, :campaign, ... ... ^
and
syntax error, unexpected ')', expecting keyword_end ...true}, {class: 'form-control'}) );@output_buffer.safe_append... ... ^
Any ideas?
Thanks in advance!
Upvotes: 0
Views: 99
Reputation: 44581
It should be:
Campaign.where(brand: b.company).where('valid_until < ?', Time.now)
Or:
Campaign.where('brand = ? and valid_until < ?', b.company, Time.now)
Upvotes: 2