I trying to create the conditions of my search, but I have some troubles.
This is the method I'm trying to create in my model.
def self.searchadv(title, place, category, date)
!title.blank? ? conditions = ['title LIKE ?', "%#{title}%"] : conditions = []
if conditions
!place.blank? ? conditions << [' AND place LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' AND category LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' AND date LIKE ?', "%#{place}%"] : conditions << []
else
!place.blank? ? conditions << [' place LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' category LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' date LIKE ?', "%#{place}%"] : conditions << []
end
find(:all, :conditions => conditions)
end
I get this error
wrong number of bind variables (4 for 1) in: title LIKE ?
if I delete this:
if conditions
!place.blank? ? conditions << [' AND place LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' AND category LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' AND date LIKE ?', "%#{place}%"] : conditions << []
else
!place.blank? ? conditions << [' place LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' category LIKE ?', "%#{place}%"] : conditions << []
!place.blank? ? conditions << [' date LIKE ?', "%#{place}%"] : conditions << []
end
Everything works great, but I need this other options in order to create my search and I don't undertand why the error is in the "LiKE"
Does anyone could help me please?
Thanks in advance!
def self.searchadv(title, place, category, date)
klass = scoped
klass = klass.where(conditions for title here) if title.present?
klass = klass.where(conditions for place here) if place.present?
klass = klass.where(conditions for category here) if category.present?
klass = klass.where(conditions for date here) if date.present?
scoped
end
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/6upZgpqP5hMJ.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/6upZgpqP5hMJ.
For more options, visit https://groups.google.com/groups/opt_out.
--
-------------------------------------------------------------
visit my blog at http://jimlabs.heroku.com