views:

428

answers:

3

is it true that Rails depend on cookies? It seems that flash is a part of session, and session uses cookies... so when i disable cookie in Firefox, a Rails app that was working shows

[error] ActionController::InvalidAuthenticityToken

so is it true that for a RoR app to work, cookies are mandatory?

Update: or, to make the Rails app work again, what is the simplest way? (and if it is one server only (Apache running mod_rails), then is it easier?)

+5  A: 

They are not mandatory, but there are some things you can't do without cookies. You can turn the authenticity tokens off as described here.

jshen
+2  A: 

It's not mandatory to use cookies, but it is the rails default from 2.x up. Using cookies serves as a simple solution to some more difficult problems that arise when you try to store cookies in memory on multiple servers (and you get into things like sticky sessions, losing user data etc).

You can set where rails stores your session data; that is the flash and anything that's associated with the specific user. In environment.rb you can configure where you store your sessions using the *config.action_controller.session_store*. The options for this are: *:cookie_store, :active_record_store, :p_store, :drb_store, :mem_cache_store, or :memory_store*.

cookie_store is the default, if you comment the option out or remove it from environemnt.rb. It's also the most versatile. If you have multiple servers, one request for a user might come into one server, and the next request might come into a different server. In this situation, you couldn't use memory_store, as the 2nd server wouldn't know anything about the current user.

By storing session information in an encrypted cookie, there is less load on the server to store this information. The only downside is that each request to the server needs to pass the cookie (usually <1k), but it's not a noticeable difference in anything I've ever experienced.

:cookie_store, :mem_cache_store and :active_record_store are the most commonly used ones.

AdamFortuna
A: 

Hi nice post and good information about sessions. can i know what is the maximum size of the cookie store? i.e how much information you can store in cookies.

Thank You, Uma.

Uma Mahesh