Forum: Ruby on Rails Basic question: Where to initialize a flag?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
90d386f9d88787fbda3ecb86228cbc08?d=identicon&s=25 David T-l (davidtl)
on 2006-02-18 19:58
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?
8e44c65ac5b896da534ef2440121c953?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-02-18 21:37
(Received via mailing list)
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 Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
ezra@yakima-herald.com
509-577-7732
90d386f9d88787fbda3ecb86228cbc08?d=identicon&s=25 David T-l (davidtl)
on 2006-02-18 21:50
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 Zygmuntowicz 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 Zygmuntowicz
> WebMaster
> Yakima Herald-Republic Newspaper
> ezra@yakima-herald.com
> 509-577-7732
1e99128ebac5ca41c91940291d315332?d=identicon&s=25 Luke Redpath (Guest)
on 2006-02-19 02:55
(Received via mailing list)
> 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.
90d386f9d88787fbda3ecb86228cbc08?d=identicon&s=25 David T-l (davidtl)
on 2006-02-19 15:37
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 Redpath 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.
This topic is locked and can not be replied to.