Forum: Ruby on Rails Another session question

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Scott Phelps (Guest)
on 2005-12-15 20:19
(Received via mailing list)
I want to give a user a form to create a new Product, but instead of
persisting the product to the database I want to store it in a
session first for category assignment, etc.. (in other controllers)

So when the user describes the product on the form I have a "Save and
Continue" button pointing to the action add_to_product_factory:

def new_product
   @product = get_product

def add_to_product_factory
   @product = Product.find(params[:product])

   ## Will the code below grab the
   ## original Product Object
   @product = get_product

   ## Here I want to determine the action based on what
   ## tab the user clicked on to continue the process
   redirect_to(:action => ????)

   def get_product
   session[:product_in_progress] ||=

Thanks in advance!
Tom D. (Guest)
on 2005-12-15 23:45
(Received via mailing list)
Hi Scott,

I am not really sure what you are asking.  Are you asking how to
redirect to another controller?  Or are you asking the best way to
capture the tab the user pressed and then forward to some controller?
If you are looking for something like this, I would say the tab
information could be sent up as a param, such as params[:tab], and you
could redirect to various controllers based on the value sent up using
something like:

  redirect_to(:controller => 'controller_a', :action => 'action_a') if
params[:tab] == 'a'
  redirect_to(:controller => 'controller_b', :action => 'action_b') if
params[:tab] == 'b'

However, another option may be to store this logic in your product
model, so that no matter where you store your products from, you could
assign the category within the model.

Hope that helps.

Scott Phelps (Guest)
on 2005-12-16 00:37
(Received via mailing list)
On Dec 15, 2005, at 4:41 PM, Tom D. wrote:
> However, another option may be to store this logic in your product
> model, so that no matter where you store your products from, you could
> assign the category within the model.

That sounds more ideal.  Let me be more specific....
Note I am switching from Product to Project now

I have a models set up like this:
class Project < ActiveRecord::Base
   has_one :contractor_item, :dependent => true
   has_one :billing_item, :dependent => true
   has_one :engineer_item, :dependent => true
class ContractorItem < ActiveRecord::Base
   belongs_to :project
class BillingItem < ActiveRecord::Base
   belongs_to :project
class EngineerItem < ActiveRecord::Base
   belongs_to :project

Now, to create a new Project I have these views:

 >>> These views are set up as CSS tabs that the user can click
between and modify before clicking a "Create Project" link.

The goal is to collect all of the form data in a session and have
that form data repopulated during the Project creation until the user
clicks "Create Project" upon which the session will be reset and the
Objects will get saved to the database (after validation - of course)

I would love to do this all in the Project model, but I could not
find how to add these multiple objects to the same session within one
Project Model.

Tom D. (Guest)
on 2005-12-16 14:17
(Received via mailing list)
Hi Scott,

Perhaps you can just store the individual params in the session such as:

And then when all of your information is collected, you could have
your project model be responsible for creating its dependencies, such

  Project.create(session[:new_contractor], session[:new_billing],

The Project model would then create each of the individual
dependencies.  You could then wrap them all in a transaction so that
if one fails, they all will.  You could also perform any business
logic related to storing these objects withing that method.

This topic is locked and can not be replied to.