3

I want to do a multi-step form for taking in new information. One page I want to collect name/contact info, the next page I want to collect medical history, the third page demographic information.

I've installed the Wizard gem and generated a dedicated controller. All of the tutorials I've seen on it apply to devise and the signup process so I'm a little bit lost on the controller actions and the instance variables and how I should be writing them.

Was wondering if anyone has a tutorial other than a sign-up one that could maybe help me along in learning how to get this all wired up.

Any pointers or assistance is appreciated.

EDIT:

I think my problem is in the controller for my wizard.

In the show and update actions the demo shows to declare the variable of

@user = current_user

That's great, but it's a helper method that I don't need. I need to create a patient, store the patient_id in a session which I do in my create action in my main patients controller. Then somehow pass that over to the patientsteps controller.

Here's what I've tried in patientsteps

class PatientstepsController < Wicked::WizardController
  before_filter :authenticate_user!

  steps :medical, :summary

  def show
    @patient = Patient.find(params[:patient_id])
    render_wizard
  end

  def update
    @patient = Patient.find(params[:id])
    @patient.attributes = params[:patient]
    render_wizard @patient
  end
end

When I do this, I get cannot find a patient without and ID. I understand that I'm doing this wrong, but I'm not sure how to pass in the patient_id that was created in my patients controller create action.

Patients Controller Create:

 def create
    @patient = Patient.new(params[:patient])

    if @patient.save
        session[:patient_id] = @patient.id
        redirect_to patientsteps_path, notice: "Patient was successfully created."
      else
        render :new
     end
  end
nulltek
  • 3,247
  • 9
  • 44
  • 94

1 Answers1

2

In your show action, instead of params[:patient_id] you should use session[:patient_id], because the id of the patient is stored in the session, not in the params hash.

Then in the update action, you will receive the patient id in params[:patient_id], not [:id], because wicked uses params[:id] to identify which step the wizard is on.

tommyalvarez
  • 615
  • 6
  • 19