Forum: Ruby on Rails @session deprecation and markaby

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.
Ben Munat (Guest)
on 2007-01-30 19:54
(Received via mailing list)
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
3aafbe7cb5c02d2a214166630afe90ac?d=identicon&s=25 Stephen B. (steveb)
on 2007-01-30 20:42
(Received via mailing list)
>  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
Jamie Orchard-Hays (Guest)
on 2007-01-30 21:24
(Received via mailing list)
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.
Ben Munat (Guest)
on 2007-01-30 21:57
(Received via mailing list)
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
Ben Munat (Guest)
on 2007-01-30 21:59
(Received via mailing list)
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
Ben Munat (Guest)
on 2007-01-31 00:47
(Received via mailing list)
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 (Guest)
on 2007-01-31 01:23
(Received via mailing list)
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 (Guest)
on 2007-01-31 01:45
(Received via mailing list)
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
This topic is locked and can not be replied to.