I'm trying to build a user sign-up page that will span three pages and create two records, a user object and a ticket object:
- the first (index) collects just one summary field of the problem.
- the second (signup_a) collects the detail description of the problem, autopopulates the summary from previous, a few associated details that will go in the ticket object, and the firstname/lastname/email that will go in the user object
- the third (signup_b) adds more detail to the user object such as address, city, state, etc. but no more details are added to the ticket object, so it could be closed out here.
- the final page (signup_c) displays all the user/ticket details back to the client and saves after a confirm button.
Currently, I have the methods in a single controller (code simplified without error-checking or respond_to):
def index # Collects summary
@ticket = Ticket.new
end
def signup_a # Basic Ticket Info/User name and email
@ticket = Ticket.new(params[:ticket])
@user = User.new
end
def signup_b # Address and other misc. pref's
@ticket = Ticket.new(params[:ticket])
@user = User.new(params[:user])
end
def signup_c #Display final results
@ticket = Ticket.new(params[:ticket])
@user = User.new(params[:user])
end
def submit_ticket #Saves info
@ticket = Ticket.new(params[:ticket])
@ticket.save!
@user = User.new(params[:user])
@user.save!
end
The problem is... I don't want to save info into the DB at every single step, only the last, but the variables from each page before that aren't explicitly referenced in the next page aren't being passed. How do I keep adding to the Ticket and User objects so the info stays until the very last page where I do one save! ? Also, when I perform a @user.save! method... can I still call on the individual attributes from the instance or does performing a save! turn the object into a true/false value based upon whether the info was stored?