Re: Re: Creating queries

If you do redirect, you lose all the instance
variables in q2. I would say go directly to list, and
make a function call from there:

def list
q2
#any other list-specific actions
end

that will let the controller access the q2 variables
from the list action.

cheers,
B Gates

Hi again! I am able to create the query string
correctly now for the
conditions. I’d like to use my common list function
to show the
records. So, what I’d like to do is call a set of
different functions
that create the correct search conditions based on
what is entered in
the forms.

But, although I’m able to construct the query in a
controller function
called ‘query1’ - unfortunately this does not work:

def q2
id = params[:id]

  qa = ['name like ?']
  sid = '%' + params[:name] + '%'
  @qp = [sid]
  qa << 'test_date >= ?'
  @qp << params[:start]
  @condition = [qa.join(' and ')] + @qp

  params[:condition] = @condition
  redirect_to :action => 'list2'

end

I’m confused whether I should use:
redirect_to :action => ‘list2’
or
render :action => ‘list2’

On the other side, list2 picks it up and uses it for
the pagination (if
I put the above code into list2 it works fine)
@condition = params[:condition]
@kx21_result_pages, @kx21_results =
paginate(:kx21_results,

:per_page => 20,

:conditions =>
@condition,

:order_by =>
@sort_order)

How do I pass the conditions array as a parameter to
the redirect?

It does work if I ‘render :action => list2’ into the
function that
creates the query (q2 above) - but, then I must
duplicate the code that
checks and creates the strings for the sort order,
etc… I guess I
could DRY it up?


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

B Gates wrote:

from the list action.

cheers,
B Gates
Thanks! Would it be a good idea to have a hidden variable then which
points out what query it is and use that in my list function to decide
which condition creating function should be called?

def list
if Request.post?
if query_requested == ‘name’ condition = q2
if query_requested == ‘date range’ condition = q3

end #conditions have been created…

   #and all the rest of the stuff either for GET or for using the

conditions…
end

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