# Global Variables for a Search Toggle?

**URL:** <https://www.ruby-forum.com/t/global-variables-for-a-search-toggle/130168>\
**Category:** Rails\
**Created:** [February 26, 2008, 1:43am UTC](https://www.ruby-forum.com/t/global-variables-for-a-search-toggle/130168 "2008-02-26T01:43:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [February 26, 2008, 1:43am UTC](https://www.ruby-forum.com/t/global-variables-for-a-search-toggle/130168/1 "2008-02-26T01:43:41Z")

</div>

Hi, i’m adding a searching part to my app and need to give the user an  
easy way to toggle between searching by Registered / Activity

Basically there will be a line of text at the top saying ‘Searching by :  
Registered’, when the user clicks Registered (a link) it will revert it  
to searching by Activity, and vice versa.

Should be simple enough but i’ve experimented with cookies and global  
variables in Ruby and getting nowhere fast.

Should basically be a method which is fired when the user clicks the  
link and in turn flips a variables value from 1 to 0 and back again.

Any ideas, stumped,

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [February 26, 2008, 6:08am UTC](https://www.ruby-forum.com/t/global-variables-for-a-search-toggle/130168/2 "2008-02-26T06:08:24Z")

</div>

John G. wrote:

> Hi, i’m adding a searching part to my app and need to give the user an  
> easy way to toggle between searching by Registered / Activity
> 
> Basically there will be a line of text at the top saying ‘Searching by :  
> Registered’, when the user clicks Registered (a link) it will revert it  
> to searching by Activity, and vice versa.
> 
> Should be simple enough but i’ve experimented with cookies and global  
> variables in Ruby and getting nowhere fast.
> 
> Should basically be a method which is fired when the user clicks the  
> link and in turn flips a variables value from 1 to 0 and back again.
> 
> Any ideas, stumped,

def toggle\_regisistered\_activity  
session[:reg\_ac] ||= false  
(session[:reg\_ac] = !session[:reg\_ac]) ? (:registerd) : (:activity)  
end

hth

ilan

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [February 26, 2008, 10:27am UTC](https://www.ruby-forum.com/t/global-variables-for-a-search-toggle/130168/3 "2008-02-26T10:27:04Z")

</div>

Ilan B. wrote:

> John G. wrote:
> 
> > Hi, i’m adding a searching part to my app and need to give the user an  
> > easy way to toggle between searching by Registered / Activity
> > 
> > Basically there will be a line of text at the top saying ‘Searching by :  
> > Registered’, when the user clicks Registered (a link) it will revert it  
> > to searching by Activity, and vice versa.
> > 
> > Should be simple enough but i’ve experimented with cookies and global  
> > variables in Ruby and getting nowhere fast.
> > 
> > Should basically be a method which is fired when the user clicks the  
> > link and in turn flips a variables value from 1 to 0 and back again.
> > 
> > Any ideas, stumped,
> 
> def toggle\_regisistered\_activity  
> session[:reg\_ac] ||= false  
> (session[:reg\_ac] = !session[:reg\_ac]) ? (:registerd) : (:activity)  
> end
> 
> hth
> 
> ilan

thanks, i’ll try that out.

fingers crossed.
