Hi,
I would like to pass the query string from action to action. For
example, the following will work in my Devices controller.
session[:query_string] = :all
@devices = Device.find(session[:query_string])
But I don’t know how to assign session[:query_string] a value when the
query becomes more complex. For example:
session[:query_string] = :all, :order => ‘rack_number asc,
rack_position desc’
@devices = Device.find(session[:query_string])
I’ve tried the usual quotation marks and such and have been having no
luck. Thanks!
Sean
session will save a value
example :
session[:customer_id] = @customer.id
if you want session to save your query you can use like this :
session[:my_query] = Customer.find(:all, :condition=>[“state = ?”,
“WA”])
you should remember that when you use find :All the result will be array
of hashing, so that you need to call each hashing by indexing array
example.
session[:my_query][0].first_name (the result will be first name at first
index)
unless you save query in single searching like
session[:my_query] = Customer.find_by_ssn(555444332)
then you only need to do :
session[:my_query].first_name
I think that all you need, sorry if my answer does not answer your
question.
GoodLuck Buddy,
Reinhart
http://teapoci.blogspot.com
That’s definitely on the right track to what I am looking for, but I
think I was having issues passing a session that was large.
For instance if I have one action:
@device = Device.find(:all, :order => 'rack_number asc, rack_position
desc)
I could do:
session[:my_query] = @device
But I think this has issues as the session that is being passed can
potentially be huge. I would prefer to do something like:
session[:my_query] = ':all, :order => ‘rack_number asc, rack_position
desc’
@device = Device.find(session[:my_query])
This would allow me to pass only the query string as a session.
However, when I do this, session[:my_query] is treated like a string
as opposed to the hash parameters.
Essentially, I am trying to save the hash parameters to the session
without the single quotes…and that is what’s stumping me.
Thanks!
Sean
On Jun 5, 8:17 pm, Rails T. [email protected]
Thanks! I think that would be one way to do it, but I was having
issues retrieving the result of the query from the session. What I
really wanted to do was store just the query itself into a session
variable.
The main problem I was having was that if I stored my find parameters
as as string, this find function was reading the strings instead of
the symbols.
Anyway…what I ended up doing was storing the queries as a SQL
statement instead of hash symbols. They using the function
find_by_sql instead of find.
For instance:
sql_query = “SQL STATEMENT”
session[:sql_query] = sql_query (not sure if this session is available
immediately after creation, so I stored it in a separate step)
@device = Device.find_by_sql(sql_query)
Now if another action wanted to be dynamic and use the results from
the prior action, it would use:
@device = Device.find_by_sql(session[:sql_query])
I’m sure there is a more elegant way to do this (and I would still be
interested to know), but this works for my purpose.
Thanks!
Sean
On Jun 5, 8:17 pm, Rails T. [email protected]
On Jun 6, 1:00 am, Sean C. [email protected] wrote:
session[:query_string] = :all, :order => ‘rack_number asc,
rack_position desc’
Well you;ve got to decide what you’re storing. for example
for example
session[:query_string] = [:all, {:order => ‘rack_number asc,
rack_position desc’}]
would work fine.
Fred