Ana Kovatcheva
2005-Jul-31 14:17 UTC
Yet Another Newbie Question ... about storing stuff in sessions
Hi folks, sorry for annoying you with such idiot questions, but i tried to google for that stuff 5 hours and for some reason (probably stupidity) I could not get it. So here is the question: I have a still small rails app with some users and settings etc. which is doing fine. Untill now everything that I''ve done with it was stored in some database tables. Now I need the users to fill out a form with data, which I don''t want to store in the database. This data is supposed to be some kind of query for a ruby clusterer which is yet not implemented. A user should be able to submit many different requests per session The form has some text fields like: string1, string2, string3 I have model requst.rb: class Request < ActiveRecord::Base attr_reader :settings belongs_to :user end ..and a RequestController: class RequestController < ApplicationController before_filter :login_required # private def new Request.new end end. How can I store (and overwrite the next time) the submitted form values in the session? Is the session the right place for holding such data? best regards Ana
Michael Walker
2005-Jul-31 14:32 UTC
Re: Yet Another Newbie Question ... about storing stuff in sessions
As far as manipulating session data, it''s as easy as:
@session[:mydata] = ''some data here''
And then on some other random page you could do:
Hey look this is an html page, the session has
<%=h @session[:mydata] %>
See the RubyOnRails wiki at:
http://wiki.rubyonrails.com/rails/show/UnderstandingSessions
@session can be indexed using strings, symbols, or whatever
As far as your specific data storage needs, consider the differences
between the following:
1. Storage in a database
* Persists forever
* More resource-intensive than storage in memory for store/
retrieve
* Less resource-intensive than storage in memory for large
data sets.
2. Storage in the client''s session
* Can only be seen by the client
* Disappears when the client''s cookie expires (assume a couple
of hours)
* Must be able to be Marshalled (no Procs)
3. Storage in the application''s session
* Viewable by the entire application
* Unless managed, disappears when the server is restarted
I forget at the moment how to persist application-context state within
rails, but a few minutes on the RoR wiki should give you an answer, or
someone else might chime in :)
Cheers,
Michael Walker
On Jul 31, 2005, at 10:17 AM, Ana Kovatcheva wrote:
> Hi folks,
>
> sorry for annoying you with such idiot questions, but i tried to
> google for that stuff 5 hours and for some reason (probably stupidity)
> I could not get it.
> So here is the question:
>
> I have a still small rails app with some users and settings etc. which
> is doing fine. Untill now everything that I''ve done with it was
stored
> in some database tables.
> Now I need the users to fill out a form with data, which I don''t
want
> to store in the database. This data is supposed to be some kind of
> query for a ruby clusterer which is yet not implemented. A user should
> be able to submit many different requests per session
>
> The form has some text fields like:
> string1, string2, string3
> I have model requst.rb:
>
> class Request < ActiveRecord::Base
> attr_reader :settings
> belongs_to :user
> end
>
> ..and a RequestController:
>
> class RequestController < ApplicationController
> before_filter :login_required
>
> #
> private
> def new
> Request.new
> end
> end.
>
> How can I store (and overwrite the next time) the submitted form
> values in the session? Is the session the right place for holding such
> data?
>
> best regards
>
> Ana
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>