# @session deprecation and markaby

**URL:** <https://www.ruby-forum.com/t/session-deprecation-and-markaby/83922>\
**Category:** Rails\
**Created:** [January 30, 2007, 7:54pm UTC](https://www.ruby-forum.com/t/session-deprecation-and-markaby/83922 "2007-01-30T19:54:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [January 30, 2007, 7:54pm UTC](https://www.ruby-forum.com/t/session-deprecation-and-markaby/83922/1 "2007-01-30T19:54:41Z")

</div>

Hi,

Rails 1.2 is barking at me to use session[:foo] instead of  
@session[:foo]. (Actually, to be exact, it’s saying “@session is  
deprecated! Call session.[] instead of @session.[]” but session.[] makes  
no sense at all, right?).

I would love to change this, but I’m using markaby for all my templates,  
and if I remove the @ from session I get a nil object.

Any ideas how to deal with this?

Ben

---

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [January 30, 2007, 8:42pm UTC](https://www.ruby-forum.com/t/session-deprecation-and-markaby/83922/2 "2007-01-30T20:42:46Z")

</div>

> but session.[] makes  
> no sense at all, right?).  
> I guess that’s slightly misleading but it’s because ‘[]’ is actually a  
> method call - like mystring.length.

> I would love to change this, but I’m using markaby for all my templates,  
> and if I remove the @ from session I get a nil object.  
> Where abouts do you get the nil object? Could you post the section of  
> code that causes the error? It’d also be good to see the code you’re  
> using to set the session variable.

Steve

---

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [January 30, 2007, 9:24pm UTC](https://www.ruby-forum.com/t/session-deprecation-and-markaby/83922/3 "2007-01-30T21:24:52Z")

</div>

under the covers, ruby turns methods like “.[]” and “.=” into “[]”  
and “=”

If session() isn’t available in Markaby, I’d send in a patch and bug  
report/feature request and monkey-patch my local installation if the  
deprecation warning is really bugging you.

---

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [January 30, 2007, 9:57pm UTC](https://www.ruby-forum.com/t/session-deprecation-and-markaby/83922/4 "2007-01-30T21:57:54Z")

</div>

Looks like my co-worker actually solved this. Apparently markaby doesn’t  
get access to the same helpers as rhtml.

So, we were trying to change this:

link\_to “Log Out”, { :controller =\> ‘login’, :action =\> ‘logout’ } if  
@session[:user\_id]

to this:

link\_to “Log Out”, { :controller =\> ‘login’, :action =\> ‘logout’ } if  
session[:user\_id]

but this ultimately worked:

if #{helpers.session[:user\_id]}  
link\_to “Log Out”, { :controller =\> ‘login’, :action =\> ‘logout’ }  
end

It’s too bad that this deprecation makes markaby code uglier.

b

---

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [January 30, 2007, 9:59pm UTC](https://www.ruby-forum.com/t/session-deprecation-and-markaby/83922/5 "2007-01-30T21:59:54Z")

</div>

Jamie Orchard-Hays wrote:

> under the covers, ruby turns methods like “.[]” and “.=” into “[]”  
> and “=”

Yeah, I guess I figured that… it’s just kind of funny that the  
deprecation message says that, since session.[] won’t compile.

> If session() isn’t available in Markaby, I’d send in a patch and bug  
> report/feature request and monkey-patch my local installation if the  
> deprecation warning is really bugging you.

Yeah, I think I’ll have to do that, since the solution  
(#{helpers.session[]}) is pretty ugly.

thanks,

b

---

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [January 31, 2007, 1:23am UTC](https://www.ruby-forum.com/t/session-deprecation-and-markaby/83922/6 "2007-01-31T01:23:14Z")

</div>

Ok, answering my own question (and for anyone else who happens upon this  
issue)…

First, the #{} needs to be in quotes and returns a string… so I needed  
to do

if !“#{session[:user\_id]}”.nil? …

Second, markaby doesn’t seem to get all the helpers unless it includes  
an rhtml file (the rhtml parser instantiates the helpers I would  
imagine).

There’s actually a patch for this in the markaby trac:

[http://code.whytheluckystiff.net/markaby/ticket/51](http://code.whytheluckystiff.net/markaby/ticket/51)

However, I think I’m not going to do the patch and wait for markaby to  
put the fix into it’s repository. (Hopefully it can be fixed in  
markaby… the patch is to builder.rb!)

In the meantime, I’ve found this hackish workaround: if my main layout  
page includes an empty .rhtml template, the helpers are made available.  
Dorky, I know… but it works for now.

b

---

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [January 31, 2007, 1:45am UTC](https://www.ruby-forum.com/t/session-deprecation-and-markaby/83922/7 "2007-01-31T01:45:15Z")

</div>

Ack… sorry… one more correction. The _only_ issue is that of markaby  
not getting rails helpers by default. Either applying the patch or  
including at least one rhtml partial in every page (main layout, for  
example) solves the problem. The #{} isn’t necessary.

b

---

<div class="post-metadata">

**Author:** ![glenatron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/94ad74/32.png) [@glenatron](https://www.ruby-forum.com/u/glenatron)\
**Post date:** [January 31, 2007, 12:47am UTC](https://www.ruby-forum.com/t/session-deprecation-and-markaby/83922/8 "2007-01-31T00:47:12Z")

</div>

Er, on the other hand… not sure if this is working after all. It  
compiles but I think the if block is always true. Need to dig into  
exactly how the #{} construct works.

In the meantime, if why or any other markaby heads are lurking, would  
love to know how they’re dealing with this.

I guess really what my question is is how does one get ahold of the  
helpers from a markaby template. Actually I thought the helpers where  
available directly markaby (like I’m using link\_to, etc.), but it  
definitely doesn’t seem to work for session.

Any help much appreciated,

Ben
