Search with more then one argument

I’am trying to create a search sytem with two arguments
When one argument is choosen it needs find all the objects with that
and when two choosen it needs to find all objects with both arguments.

In my view

<% form_tag :action => ‘tuinen’, :method => ‘get’ do %>
<%= options = [[“Selecteer een provincie”, “”]] + User::PROVINCES
select(“search”, nil, options)
<%= select ‘heading’, nil, Heading.find(:all).collect {|p| [, ] }, { :prompt => “selecteer een rubriek”} %>
<%= submit_tag “Zoek mijn tuin”%>

<% end %>

the problem is into my controller i can’t find no way to seperate the
i tried several methods but nothing works

my basic method is like this

if @params[:search]
@gardens = Garden.find(:all, :conditions => {:provincie =>
@params[:search], :heading_id => @params[:heading], :destroyed => 0})

I think you might want something like

@gardens = Garden.find(:all, :conditions => [“provincie = ? and
heading_id = ? and destroyed = 0”, @params[:search],
@params[:heading] ]

This variant of :conditions creates a SQL fragment for a where clause
that replaces the ?'s in order with the values provided after the
first comma (and has the added benefit of preventing SQL injection).

Is the what you were looking for?


On Dec 20, 11:53 am, GA Gorter [email protected]

Whoops – I missed a closing ) after the last ]


It does not what i want

I want a system when i choose only a province i get all gardens in that
specific province
And when i set the heading i get all gardens with that specific heading
And when i set them both i get all gardens in that province and that

In this way only when i set both i get the right results even like the
system i had in the post above.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs