Ruby, how do I split a simple_form with multiple fields across multiple screens so it's 1 field per screen

150 views Asked by At

Could not find the answer for how to split a simple_form across multiple screens so that it's one form per screen, then you confirm.

I have a big form with:

  • First field requires you to select an option from a dropdown
  • Second field is an input
  • Third field is a date picker
  • Fourth field is free text
  • Submit button

I'd like this to be split across four screens so it's less overwhelming for the user, and it just looks nicer. What would be the best way to do that?

Thanks so much!

1

There are 1 answers

0
Inba On

I have worked on a similar requirement and this seems to work for us.

in controller..

def new
  ...
end

def create
  record.step = 1
  # create record
  ...
  render step_2
end

def step_2
  ...
end

# POST /controller/:id/update_step_2
def update_step_2
  record.step = 2
  # update object
  ...
end

step is a attr_acessor in model. This will be used in validation conditions.