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 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Terrorist <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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, > > Reinharthttp://teapoci.blogspot.com > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 6, 1:00 am, Sean Chon <chons...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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''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 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---