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? -- Posted via http://www.ruby-forum.com/.
Ezra Zygmuntowicz
2006-Feb-18 20:34 UTC
[Rails] Basic question: Where to initialize a flag?
On Feb 18, 2006, at 10:58 AM, David T-L wrote:> 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? > > --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
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-- Posted via http://www.ruby-forum.com/.
Luke Redpath
2006-Feb-19 01:54 UTC
[Rails] Re: Basic question: Where to initialize a flag?
> 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. On 2/18/06, David T-L <dtl@stanfordalumni.org> wrote:> > 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 > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers, Luke Redpath www.lukreedpath.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060219/9c65488c/attachment.html
David T-L
2006-Feb-19 14:38 UTC
[Rails] Re: Re: Basic question: Where to initialize a flag?
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.-- Posted via http://www.ruby-forum.com/.