0

There must be something about helpers in Sinatra I'm not understanding, but wondering why this doesn't work:

helpers do
  def session_access_token
   p "GETTING: #{@app_id}_#{@page_id}"
   session["access_token_#{@app_id}_#{@page_id}"]
  end

  def session_access_token=(v)
    p "Setting: #{@app_id}_#{@page_id} access token to: #{v}"
    session["access_token_#{@app_id}_#{@page_id}"] = v
  end
end

Then, in an action like this:

get '/' do
 session_access_token = 'foo'
 p session_access_token
end

I see neither get called (seems like it's creating a new local variable). That said, when I call 'session_access_token' in other actions, I do see the getter is called.

Any advice would be appreciated.

Tom Lianza
  • 4,012
  • 4
  • 41
  • 50
  • If, instead of "session_access_token=" I change it to a method named "set_session_access_token" and call it, that works. Perhaps helpers don't let you define/use methods like this? – Tom Lianza Dec 25 '11 at 04:21

1 Answers1

1

As described on the Sinatra issue: something = something_else never translates into a method call in Ruby. You have to write self.something = something_else.

Konstantin Haase
  • 25,687
  • 2
  • 57
  • 59