Hi,
I am trying to build a search form with multiple field input. And while
the single field search is working just fine, I am having some issues
creating the WHERE with the two fields joined. Here is the code.
def index
@cities = City.order("province_id, name").page(params[:page])
# Need to create this condition for now I have added a place holder.
if (!params[:name_like].blank?) && (!params[:province_like].blank?)
@cities = City.order("province_id, name").page(params[:page])
# This if works just fine
elsif !params[:name_like].blank?
@cities = City.where(:name.matches => (''%'' +
params[:name_like] +
''%'')).order("province_id, name").page(params[:page])
# This if works just fine
elsif !params[:province_like].blank?
@cities = City.joins(:province).where(:province => {:name.matches
=> (''%'' + params[:province_like] +
''%'')}).order("province_id,
name").page(params[:page])
end
end
Also is there a better way to write the same piece of code?
--
Posted via http://www.ruby-forum.com/.
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.