Problems with flash/session in a canvas application

12 views
Skip to first unread message

Thorbjørn

unread,
Jan 24, 2010, 6:56:54 AM1/24/10
to facebooker
Hi,

I have a problem with flash/session in a facebooker application
running Rails 2.3.5. When I first started my little facebooker project
I had a problem with setting flashes: When I did set the for example
flash[:notice] = "Post saved" and then redirected the user to posts'
index page the flash didn't show.

After some time I figured out that I could fix this by changing the
session store from cookie to Active Record session store. This worked
perfect; I got my flashes out and when I took a look in the sessions
table in my database I got one row per user.

But now all of a sudden one user gets a new session per request; the
sessions table grows +1 per request even though I am the only one
accessing my development canvas application. I can't really say that I
have done anything different from before when it worked and I have
also checked out old versions of my code back to when I know that it
worked fine! I have also tried older versions of facebooker (I'm
currently on 1.0.61, but have also tried 1.0.58 which is the one I
used when it worked).

Have anyone experienced this too, or have any solutions I can try to
fix this?

martio

unread,
Jan 26, 2010, 8:32:58 AM1/26/10
to facebooker
On 24 Sty, 12:56, Thorbjørn <thherman...@gmail.com> wrote:
> I have a problem with flash/session in a facebooker application
> running Rails 2.3.5. When I first started my little facebooker project
> I had a problem with setting flashes: When I did set the for example
> flash[:notice] = "Post saved" and then redirected the user to posts'
> index page the flash didn't show.

I have the same problem with displaying a flash messages after
redirect with RoR 2.3.5 and latest version of the Facebooker plugin...

Martio

Mike Mangino

unread,
Jan 26, 2010, 8:39:36 AM1/26/10
to faceb...@googlegroups.com
Was this working on previous versions? There was a change added for session handline in the rack extensions. Can you try removing that from the rack_setup.rb file (it's the second setup part) to see if that fixes it?

Mike

> --
> You received this message because you are subscribed to the Google Groups "facebooker" group.
> To post to this group, send email to faceb...@googlegroups.com.
> To unsubscribe from this group, send email to facebooker+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/facebooker?hl=en.
>

--
Mike Mangino
http://www.elevatedrails.com

W. Andrew Loe III

unread,
Jan 27, 2010, 12:08:31 AM1/27/10
to faceb...@googlegroups.com
The Rack::FacebookSession middleware could be a problem depending on
when you load the file, I probably should have more thoroughly pointed
out this potential caveat before submitting this middleware.

As it stands now rack_setup.rb has this:

ActionController::Dispatcher.middleware.insert_before(
ActionController::Base.session_store,
Rack::FacebookSession,
ActionController::Base.session_options[:key]
)

Which means FACEBOOK_SESSION_KEY is changed to
ActionController::Base.session_options[:key]. Many (most?) set their
session key in an initializer which happens AFTER the plugin/gem is
loaded. You can see if you are suffering from this by running rake
middleware which might look something like this:
http://skitch.com/waloeiii/n1k56/andrew-loe-projects-onehub-caffe-bash

In my initial implementation, I used a closure to delay evaluation
until the first request, but that caused other problems in Mike's
testing so I reverted it to just eval the session key at load.

I'm not sure what the right solution is here, but what I'm doing by
default probably isn't obvious enough and should be changed. As a
quick fix you can just modify (or monkey-patch) your plugin to put a
string '_your_application_key', and it should do the right thing.
Beware if you are storing your sessions in memcache it doesn't like
the Facebook keys so you always sha1 the key (memcache-client has this
as a built in option).

Thorbjørn

unread,
Jan 27, 2010, 3:38:49 AM1/27/10
to facebooker
Thank you! It seems that this is the source of my problem (the
middleware is lacking the knowledge of what my session_key is.) And
yeah, I did session setup in the default Rail's initializer "config/
initializers/session_store.rb". I did a quick "fix" of hardcoding my
session key in "lib/facebooker/rails/extensions/
rack_setup.rb" (changing "ActionController::Base.session_options
[:key]" to a string that is) rebuilding and installing the gem and it
worked. Guess I'll do some monkeypatching instead just so I don't have
to distribute a custom gem to my servers. Again, thanks for pointing
me in the right direction on how to fix this :-)

> <mmang...@elevatedrails.com> wrote:
> > Was this working on previous versions? There was a change added for session handline in the rack extensions. Can you try removing that from the rack_setup.rb file (it's the second setup part) to see if that fixes it?
>
> > Mike
>
> > On Jan 26, 2010, at 8:32 AM, martio wrote:
>
> >> On 24 Sty, 12:56, Thorbjørn <thherman...@gmail.com> wrote:
> >>> I have a problem with flash/session in a facebooker application
> >>> running Rails 2.3.5. When I first started my little facebooker project
> >>> I had a problem with setting flashes: When I did set the for example
> >>> flash[:notice] = "Post saved" and then redirected the user to posts'
> >>> index page the flash didn't show.
>
> >> I have the same problem with displaying a flash messages after
> >> redirect with RoR 2.3.5 and latest version of the Facebooker plugin...
>
> >> Martio
>
> >> --
> >> You received this message because you are subscribed to the Google Groups "facebooker" group.
> >> To post to this group, send email to faceb...@googlegroups.com.
> >> To unsubscribe from this group, send email to facebooker+...@googlegroups.com.

> >> For more options, visit this group athttp://groups.google.com/group/facebooker?hl=en.

W. Andrew Loe III

unread,
Jan 27, 2010, 3:56:14 AM1/27/10
to faceb...@googlegroups.com
I am working on a better solution to delay evaluating this so we get
around the load order issue. Perhaps even just wrapping in a
config.after_initialize in the rails hook file? Any ideas would be
appreciated.

Thorbjørn

unread,
Jan 27, 2010, 4:04:16 AM1/27/10
to facebooker
My "fix" to this problem can be fond in my project's github
repository. To be more specific:
http://github.com/thhermansen/bruktmarked/commit/97db26d610ce99add5a7d7665c3440c5d72fe152.
I just deleted Rack::FacebookSession, and reinserted it after the
session key has been set (note the name of the file which makes it
load after session_store.rb).

martio

unread,
Feb 1, 2010, 6:52:31 PM2/1/10
to facebooker
On 27 Sty, 10:04, Thorbjørn <thherman...@gmail.com> wrote:
> My "fix" to this problem can be fond in my project's github
> repository. To be more specific:http://github.com/thhermansen/bruktmarked/commit/97db26d610ce99add5a7....

> I just deleted Rack::FacebookSession, and reinserted it after the
> session key has been set (note the name of the file which makes it
> load after session_store.rb).

This patch does not work... I'm using rails 2.3.5 and default session
store...

Martin

J. Pablo Fernández

unread,
Feb 6, 2010, 11:46:08 PM2/6/10
to facebooker

On Jan 27, 6:08 am, "W. Andrew Loe III" <and...@andrewloe.com> wrote:

> I'm not sure what the right solution is here, but what I'm doing by
> default probably isn't obvious enough and should be changed. As a
> quick fix you can just modify (or monkey-patch) your plugin to put a
> string '_your_application_key', and it should do the right thing.
> Beware if you are storing your sessions in memcache it doesn't like
> the Facebook keys so you always sha1 the key (memcache-client has this
> as a built in option).

Can you please show us how you are doing this?

Thanks.

zziemke

unread,
Mar 7, 2010, 2:02:01 PM3/7/10
to facebooker
What is the correct way to make this work?

Kainage

unread,
Mar 12, 2010, 11:38:53 PM3/12/10
to facebooker
My "fix" to this problem can be fond in my project's github
repository. To be more specific:
http://github.com/thhermansen/bruktmarked/commit/97db26d610ce99add5a7....
I just deleted Rack::FacebookSession, and reinserted it after the
session key has been set (note the name of the file which makes it
load after session_store.rb).

That worked for me.

On Mar 7, 11:02 am, zziemke <zzie...@googlemail.com> wrote:
> What is the correct way to make this work?
>
> On 7 Feb., 05:46, J. Pablo Fernández <pup...@pupeno.com> wrote:
>
> > On Jan 27, 6:08 am, "W. Andrew Loe III" <and...@andrewloe.com> wrote:
>
> > > I'm not sure what the right solution is here, but what I'm doing by
> > > default probably isn't obvious enough and should be changed. As a
> > > quick fix you can just modify (or monkey-patch) your plugin to put a
> > > string '_your_application_key', and it should do the right thing.

> > > Beware if you are storing yoursessionsin memcache it doesn't like

Reply all
Reply to author
Forward
0 new messages