@session deprecation and markaby

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

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

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.

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

Steve Bartholomew wrote:

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

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

Ben Munat wrote:

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

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

Ben Munat wrote:

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

Ben Munat wrote: