As a first test project, I''m writing a little Rails app that simply lets one browse the directory structure on the server. (Obviously, this isn''t intended for public deployment :-) ). One thing that needs to be stored in a session is the currently browsed directory. What''s the best way to store such simple data? (I sorta think a database table is overkill :-) ) Thanks, Ken --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Wang
2007-May-01 05:34 UTC
Re: Newbie question; best way to store simple session data?
ken wrote:> As a first test project, I''m writing a little Rails app that simply > lets one browse the directory structure on the server. (Obviously, > this isn''t intended for public deployment :-) ). One thing that needs > to be stored in a session is the currently browsed directory. What''s > the best way to store such simple data? (I sorta think a database > table is overkill :-) )Store it in a cookie. -- Michael Wang --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Robert Walker
2007-May-01 16:00 UTC
Re: Newbie question; best way to store simple session data?
Rails has a session management mechanism already built for you. Just
use that. Store your value in the session hash then you can just
configure Rails to store sessions either in a file (the default) or in
the database if you prefer that.
Excerpt from Agile Web Development with Rails page 105:
-----------------------------------------------------------
By default, Rails stores session information in a file on the server.
If you have
a single Rails server running, there''s no problem with this. But
imagine that
your store application gets so wildly popular that you run out of
capacity on a
single-server machine and need to run multiple boxes. The first
request from
a particular user might be routed to one back-end machine, but the
second
request might go to another. The session data stored on the first
server isn''t
available on the second; the user will get very confused as items
appear and
disappear in their cart across requests.
-----------------------------------------------------------
If you choose to store session data in the database just do this:
depot> rake db:sessions:create
exists db/migrate
create db/migrate/004_add_sessions.rb
depot> rake db:migrate
And here''s a sample of storing an object in the session:
def find_cart
unless session[:cart] # if there''s no cart in the
session
session[:cart] = Cart.new # add a new one
end
session[:cart] # return existing or new cart
end
On May 1, 1:34 am, Michael Wang
<rails-u...-JtyympAsP2K7zZZRDBGcUA@public.gmane.org>
wrote:> ken wrote:
> > As a first test project, I''m writing a little Rails app that
simply
> > lets one browse the directory structure on the server. (Obviously,
> > this isn''t intended for public deployment :-) ). One thing
that needs
> > to be stored in a session is the currently browsed directory.
What''s
> > the best way to store such simple data? (I sorta think a database
> > table is overkill :-) )
>
> Store it in a cookie.
>
> --
> Michael Wang
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---