# Basic question: Where to initialize a flag?

**URL:** <https://www.ruby-forum.com/t/basic-question-where-to-initialize-a-flag/53967>\
**Category:** Rails\
**Created:** [February 18, 2006, 7:58pm UTC](https://www.ruby-forum.com/t/basic-question-where-to-initialize-a-flag/53967 "2006-02-18T19:58:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidtl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@davidtl](https://www.ruby-forum.com/u/davidtl)\
**Post date:** [February 18, 2006, 7:58pm UTC](https://www.ruby-forum.com/t/basic-question-where-to-initialize-a-flag/53967/1 "2006-02-18T19:58:23Z")

</div>

I have found that if I initialize a flag in my controller (under def  
Initialize), it appears everytime I call a controller action, the flag  
is set to the initialize value (even though I’m not calling the  
initialized action). Am I observing this clearly?

I don’t think I should initialize a flag in the index file. So where?

Specifically, I want to know if this action is a new search (if so,  
“reset” the $new\_search flag). If not a new search, assign a value from  
one of the action parameters.

I anticipate setting the $new\_search flag to true in some other actions  
(such as clicking a New Search button). But the very first time my page  
displays, it is a “new search” and it appears the $new\_search flag  
begins life as “false”.

Perhaps I’ve made a bad assumption as I try to figure this out.

Can anyone straighten me out?

---

<div class="post-metadata">

**Author:** ![davidtl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@davidtl](https://www.ruby-forum.com/u/davidtl)\
**Post date:** [February 18, 2006, 9:37pm UTC](https://www.ruby-forum.com/t/basic-question-where-to-initialize-a-flag/53967/2 "2006-02-18T21:37:14Z")

</div>

On Feb 18, 2006, at 10:58 AM, David T-L wrote:

> one of the action parameters.  
> Can anyone straighten me out?
> 
> –

```
Sounds like you would be better off putting the new_search flag in

```

the session. Since rails is multi process you will have multiple  
users hitting the app and each one might get a differetn fcgi  
process. So there is not way to make sure the flag is set for the  
current user correctly the way you are doing it. Try putting it in  
the session instead. You can use a before\_filter to set it up initially.  
Cheers-  
-Ezra Z.  
WebMaster  
Yakima Herald-Republic Newspaper  
removed\_email\_address@domain.invalid  
509-577-7732

---

<div class="post-metadata">

**Author:** ![davidtl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@davidtl](https://www.ruby-forum.com/u/davidtl)\
**Post date:** [February 18, 2006, 9:50pm UTC](https://www.ruby-forum.com/t/basic-question-where-to-initialize-a-flag/53967/3 "2006-02-18T21:50:21Z")

</div>

Thanks, Ezra.

That makes sense. Except, I’m not even ready to explore the world of  
“sessions”. I’m trying to get the one instance up and rolling and get  
some real programmers to scale it, etc. once the issue is no longer how  
to talk to our server.

I do appreciate your help. I’ve staggered my way through and now have  
something that works. I’m not trying to do it “right”.

Dave

Ezra Z. wrote:

> On Feb 18, 2006, at 10:58 AM, David T-L wrote:
> 
> > one of the action parameters.  
> > Can anyone straighten me out?
> > 
> > –
> 
> Sounds like you would be better off putting the new\_search flag in  
> the session. Since rails is multi process you will have multiple  
> users hitting the app and each one might get a differetn fcgi  
> process. So there is not way to make sure the flag is set for the  
> current user correctly the way you are doing it. Try putting it in  
> the session instead. You can use a before\_filter to set it up initially.  
> Cheers-  
> -Ezra Z.  
> WebMaster  
> Yakima Herald-Republic Newspaper  
> removed\_email\_address@domain.invalid  
> 509-577-7732

---

<div class="post-metadata">

**Author:** ![davidtl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@davidtl](https://www.ruby-forum.com/u/davidtl)\
**Post date:** [February 19, 2006, 2:55am UTC](https://www.ruby-forum.com/t/basic-question-where-to-initialize-a-flag/53967/4 "2006-02-19T02:55:16Z")

</div>

> Except, I’m not even ready to explore the world of  
> “sessions”.

Why not? They are an essential feature that allows you to maintain state  
between requests.

I’m not quite sure of what you are trying to do here. If you want to  
maintain state between requests, use the session[] array.

---

<div class="post-metadata">

**Author:** ![davidtl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@davidtl](https://www.ruby-forum.com/u/davidtl)\
**Post date:** [February 19, 2006, 3:37pm UTC](https://www.ruby-forum.com/t/basic-question-where-to-initialize-a-flag/53967/5 "2006-02-19T15:37:59Z")

</div>

Luke,

You are absolutely right and I appreciate the fact that you emphasize  
the importance of this area.

I’m sort of sneaking up on the Ajax on Rails thing and trying to be very  
simple at first, but still having a bit of a fog about the whole  
structure, especially when the examples are not careful about using  
different names for differnt types of elements (ADWR has an example  
using “guess” both as a variable, action, and label. I know now the  
difference, but in “mirroring/learning” mode I didn’t appreciate it  
until after hours of debuging when I tried to do my own thing.

Your comment and Ezra’s about sessions (and a scolding from Tom M.) made  
me realize that I still don’t get the whole thing and I need remarks  
like yours to be stirred to the basic.

Another example, the book does a great job of saying, “no logic in the  
views”. More of that is good.

On the other hand, I kept considering index.html a “view” for everything  
and it took me awhile to realize that the actions need their own views.  
Of course I read MVC, but I hadn’t grok’d it.

Thanks again for getting us Newbies in the right church.

Luke R. wrote:

> > Except, I’m not even ready to explore the world of  
> > “sessions”.
> 
> Why not? They are an essential feature that allows you to maintain state  
> between requests.
> 
> I’m not quite sure of what you are trying to do here. If you want to  
> maintain state between requests, use the session[] array.
