Hi there, when i do this: session[:myItem] = ''foo'' session[:myItem] = nil the item :myItem is removed from the session. But this: session[''myItem''] = ''foo'' session[''myItem''] = nil doesn''t remove ''myItem'', it''s empty but still in the session. Any suggestion ? Thanks in advance. mic -- Posted via http://www.ruby-forum.com/.
On 4-jun-2006, at 17:20, mic wrote:> Hi there, > > when i do this: > > session[:myItem] = ''foo'' > session[:myItem] = nil > > the item :myItem is removed from the session. > > But this: > > session[''myItem''] = ''foo'' > session[''myItem''] = nil > > doesn''t remove ''myItem'', it''s empty but still in the session. > > Any suggestion ? > > Thanks in advance.Feels like a bug. -- Julian ''Julik'' Tarkhanov please send all personal mail to me at julik.nl
On 6/5/06, Julian ''Julik'' Tarkhanov <listbox@julik.nl> wrote:> > On 4-jun-2006, at 17:20, mic wrote: > > > Hi there, > > > > when i do this: > > > > session[:myItem] = ''foo'' > > session[:myItem] = nil > > > > the item :myItem is removed from the session. > > > > But this: > > > > session[''myItem''] = ''foo'' > > session[''myItem''] = nil > > > > doesn''t remove ''myItem'', it''s empty but still in the session. > > > > Any suggestion ? > > > > Thanks in advance. > > Feels like a bug. > > -- > Julian ''Julik'' Tarkhanov > please send all personal mail to > me at julik.nl > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >It''s not a bug - it''s a feature! ;-) Seriously: the session object is Ruby stdlib CGI::Session instance. Which is a pseudo hash, to which you can add keys, and reassign their values, but not permanently remove keys. It would be nice to be able to do it, if only for debugging dumps of #session to be cleaner. But beyond that, I can''t see any real ramifications for just clearing the values with "session[key] = nil". -- -Alder
On Sun, 2006-06-04 at 17:20 +0200, mic wrote:> Hi there, > > when i do this: > > session[:myItem] = ''foo'' > session[:myItem] = nil > > the item :myItem is removed from the session. > > But this: > > session[''myItem''] = ''foo'' > session[''myItem''] = nil > > doesn''t remove ''myItem'', it''s empty but still in the session. > > Any suggestion ? > > Thanks in advance.---- Try session[''myitem''].delete Craig
On 6/5/06, Craig White <craigwhite@azapple.com> wrote:> On Sun, 2006-06-04 at 17:20 +0200, mic wrote: > > Hi there, > > > > when i do this: > > > > session[:myItem] = ''foo'' > > session[:myItem] = nil > > > > the item :myItem is removed from the session. > > > > But this: > > > > session[''myItem''] = ''foo'' > > session[''myItem''] = nil > > > > doesn''t remove ''myItem'', it''s empty but still in the session. > > > > Any suggestion ? > > > > Thanks in advance. > ---- > Try session[''myitem''].delete > > Craig > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >It won''t work; you''re calling method delete on the object stored in session[''myitem'']. In this case, you''d be calling ''foo''.delete which is String#delete and in any case has nothing to do with the CGI::Session instance and/or its (pseudo) keys. -- -Alder
On 6/4/06, mic <mic@test.de> wrote:> Hi there, > > when i do this: > > session[:myItem] = ''foo'' > session[:myItem] = nil > > the item :myItem is removed from the session.Are you sure about that? It shouldn''t be so, and some simple checks with both debug(session) indicate it is not, exactly the same as for the string key. Moreover, note that even on a regular hash, setting key to value nil would not eliminate the key. What the CGI::Session pseudo-hash actually lacks is the Hash#delete method. Or rather, it has its own #delete, which does something else which you probably don''t want (destroy the session). Bad design decision for a pseudo-hash object, imho.> > But this: > > session[''myItem''] = ''foo'' > session[''myItem''] = nil > > doesn''t remove ''myItem'', it''s empty but still in the session. > > Any suggestion ? > > Thanks in advance. > > mic > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- -Alder
On 4-jun-2006, at 23:10, Alder Green wrote:>> > > It''s not a bug - it''s a feature! ;-) > > Seriously: the session object is Ruby stdlib CGI::Session instance. > Which is a pseudo hash, to which you can add keys, and reassign their > values, but not permanently remove keys. > > It would be nice to be able to do it, if only for debugging dumps of > #session to be cleaner. But beyond that, I can''t see any real > ramifications for just clearing the values with "session[key] = nil".By "bug" I mean the fact that the result of the two operations is not consistent. As it turns out I was wrong and you just have to use session.delete(key) just as with any Ruby hash, indifferent access or not. Case closed :-) -- Julian ''Julik'' Tarkhanov please send all personal mail to me at julik.nl
Hello, i''m struggling with the following problem: I have a edit page wich on wich a user can edit his Account information and add or remove his Subscriptions. For the time the user is editing his Subscriptions I''ll keep his subscriptions in a session. After the user has finished adding and removing subscriptions I want to have the new set of subscriptions in the session. If the user validates his modifications, i''ll write the modifications to the database. I have the following code in my accounts_controller def edit @account = Account.find(params[:id]) @subscriptions = @account.subscriptions session[:subscriptions] ||= Subscription.new session[:subscriptions] = @subscriptions end the session[:subscriptions] contains all the subscriptions that belong to a specific account. i.e. Account 1 has the following Subscriptions 1.. Subscription 1 2.. Subscription 2 3.. Subscribtion 4 4.. Subscribtion 7 My problem: If the user click on de ''Delete'' url for example on Subscription 4, i want to remove subscription 4 from the session. (So i don''t want to remove that object fysically from the database). Does anybody know how to do that? -- Posted via http://www.ruby-forum.com/.
Hello, i''m struggling with the following problem: I have a edit page wich on wich a user can edit his Account information and add or remove his Subscriptions. For the time the user is editing his Subscriptions I''ll keep his subscriptions in a session. After the user has finished adding and removing subscriptions I want to have the new set of subscriptions in the session. If the user validates his modifications, i''ll write the modifications to the database. I have the following code in my accounts_controller def edit @account = Account.find(params[:id]) @subscriptions = @account.subscriptions session[:subscriptions] ||= Subscription.new session[:subscriptions] = @subscriptions end the session[:subscriptions] contains all the subscriptions that belong to a specific account. i.e. Account 1 has the following Subscriptions 1.. Subscription 1 2.. Subscription 2 3.. Subscribtion 4 4.. Subscribtion 7 My problem: If the user click on de ''Delete'' url for example on Subscription 4, i want to remove subscription 4 from the session. (So i don''t want to remove that object fysically from the database). Does anybody know how to do that? micheldogger -- Posted via http://www.ruby-forum.com/.