Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to split devise edit form in rails app?

Kasper Valentin asked in Rails

I’m trying to split my rails devise edit form into 3 pages. But when I hit the submit button nothing happens and nothing gets saved.
Any help would be much appreciated :-)

I have created 3 edit pages in this folder views/userprofiles

user_info.html.erb

clinic_info.html.erb

practitioner_info.html.erb

In my routes I have created these routes for the new files and for the update

  get "userprofiles/user_info" => "userprofiles#user_info", as: "user_info"
  get "userprofiles/clinic_info" => "userprofiles#clinic_info", as: "clinic_info"
  get "userprofiles/practitioner_info" => "userprofiles#practitioner_info", as: "practitioner_info"


  patch "userprofiles/user_info" => "userprofiles#update"
  patch "userprofiles/clinic_info" => "userprofiles#update"
  patch "userprofiles/practitioner_info" => "userprofiles#update"

I’ve created this new controller for the purpose

class UserprofilesController < ApplicationController

def user_info
end

def clinic_info
end

def practitioner_info
end

def update
end

end

This is my form for the clinic_info page

            <div class="content clinic">
              <h2 class="page-title">Generel information</h2>       
                <div class="basic-section">

                    <%= form_for(current_user, url: clinic_info_path) do |f| %>

                    <div class="field text-field">
                        <%= f.text_field :clinic_name, autofocus: true, autocomplete: "Klinikkens navn", placeholder: "Klinikkens navn"  %>

                    </div>
                    <div class="field text-field">
                      <%= f.text_field :clinic_address, autofocus: true, autocomplete: "Adresse", placeholder: "Adresse" %>
                    </div>
                    <div class="field-group location-group">
                      <div class="field text-field">
                        <%= f.text_field :clinic_zip_code, autofocus: true, autocomplete: "Postnr.", placeholder: "Postnr." %>
                      </div>
                      <div class="field text-field">
                        <%= f.text_field :clinic_city, autofocus: true, autocomplete: "By", placeholder: "By" %>
                      </div>
                      <div class="field text-field">
                        <%= f.text_field :clinic_municipality, autofocus: true, autocomplete: "Kommune", placeholder: "Kommune" %>
                      </div>
                    </div>          
                </div>
                <div class="about-section">
                  <div class="field text-field">
                      <%= f.text_field :clinic_about, :as => :text, :input_html => { 'rows' => 5}, autofocus: true, autocomplete: "Om klinikken", placeholder: "Om klinikken" %>
                  </div>
                </div>
                <div class="field-group contact-section">
                  <div class="field text-field">
                    <%= f.text_field :clinic_mail, input_html: { autocomplete: 'email' }, autofocus: true, placeholder: "E-mail" %>
                  </div>
                  <div class="field text-field">
                    <%= f.text_field :clinic_phone, autofocus: true, autocomplete: "Tlf. nr.", placeholder: "Tlf. nr." %>
                  </div>
                  <div class="field text-field">
                    <%= f.text_field :clinic_website, autofocus: true, autocomplete: "Hjemmeside", placeholder: "Hjemmeside" %>
                  </div>
                </div>
                <div class="btn-container">
                  <%= f.submit "Save", :class => 'btn blue'  %>                 
               </div>
              <% end %>
          </div> 
Reply

Anyone?

Reply

Did you managed to solve it Kasper?

Reply

No, unfortunately i haven't been able to solve it

Reply

Kasper, does your log files give you any indication as to what is going on?

Reply

Kasper, can you tell us why you want to split the user profile into 3 different pages?

Reply

I'm new to rails, so I'm not sure how to read the log file, but this is what I get, when I hit the save button. I want to split the edit page in 3 pages for better UI, because a have a very long sign up process.

Started PATCH "/userprofiles/clinic_info" for ::1 at 2020-02-21 08:16:13 +0100
Processing by UserprofilesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"fYdVH9aY3XfQ+Fu639zhEsvrxRwYtIeYacqrKowDDlPu3r6iuXZOalFahSJ61peVBawf0DioVu+arrJzJK5M9A==", "user"=>{"clinic_name"=>"Kaspers Zoness", "clinic_address"=>"Krebsen 99", "clinic_zip_code"=>"5700", "clinic_city"=>"Svendborg", "clinic_municipality"=>"Svendborg", "clinic_about"=>"Jeg trykker på fødderne", "clinic_mail"=>"kasper@betterwing.dk", "clinic_phone"=>"24210886", "clinic_website"=>""}, "commit"=>"Gem"}
No template found for UserprofilesController#update, rendering head :no_content
Completed 204 No Content in 65ms (ActiveRecord: 0.0ms)

Reply

Hi Kasper,

The first thing that I notice is that you don't have any actions defined in your controller. Rails is trying to process UserprofilesController#update but the action empty. So that would be a start, define your actions and see what happens.

A couple of things that you should try after you resolve the first one:

  1. Your UsersController should inherit from Devise. See Devise github page: https://github.com/heartcombo/devise#configuring-controllers
  2. Make sure that you sanitize any additonal attribute from the Devise standard: https://github.com/heartcombo/devise#strong-parameters

My personal opinion is to not overly complicate your Rails code to make the UI better for the user. You can order attributes into groups on the front-end to make it easier for the user to focus, you could make tabs to seperate the groups. What I would do is use something like the Wicked gem. It helps you create a wizard type of experience for your user. Breaks the profile creation into bit-sized pieces. Richard Schneeman is the maintainer. Check out his screen cast, I think that its what you are looking for:
https://schneems.com/post/18437886598/wizard-ify-your-rails-controllers-with-wicked

I hope that my comments are helpful! Good luck!

Reply

Hi Jim, it makes sense, thank you very much for your help, appreciate it :-)

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.