Alfred
Alfred

Reputation: 7091

Problem with sessions, subdomains and authlogic in Rails

I've got a rails app with authlogic authentication and a username.domain.com structure built with subdomain-fu.

But my session breaks when going from domain.com to username.domain.com. I've tried to add

config.action_controller.session = {:domain => '.localhost:3000'}

to my development.rb but that seams to break authlogic disabling sign out/sign in.

Any suggestions on what to do?

Thanks in advance!

Upvotes: 3

Views: 2016

Answers (3)

trushkevich
trushkevich

Reputation: 2677

For Rails3 the code above will raise NoMethodError:

undefined method `session=' for ActionController::Base:Class

So, for Rails3 you should not change you environment config but should set your app/config/initializers/session_store.rb to look like:

YourAppName::Application.config.session_store :active_record_store,
    {:key => '_your_namespace_session', :domain => '.yourdomain.com'}

Upvotes: 1

Arnaud
Arnaud

Reputation: 17737

Maybe this can help: http://erikonrails.snowedin.net/?p=248 ?

Upvotes: 0

Addy
Addy

Reputation: 1851

you are having this issue in the development mode but probably wont have this issue in prod mode.. you are trying to set the top level cookie. your browser wont let you do that. what you are trying to do with

config.action_controller.session = {:domain => '.localhost:3000'}

is as good as saying

config.action_controller.session = {:domain => '.com'}

try creating custom local domain like localhost.localdomain or dummylocal.com or something and that will make it work.

config.action_controller.session = {:domain => 'localhost.localdomain'}
config.action_controller.session = {:domain => 'dummylocal.com'}

Upvotes: 1

Related Questions