Basic question: Where to initialize a flag?

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?

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
[email protected]
509-577-7732

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
[email protected]
509-577-7732

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.

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.