Разделение формы редактирования устройства на несколько страниц - PullRequest
0 голосов
/ 21 февраля 2020

Я пытаюсь разделить форму редактирования моего рельса на 3 страницы. Но когда я нажимаю кнопку отправки, ничего не происходит и ничего не сохраняется. У меня очень длинный процесс регистрации, поэтому я хочу разделить страницу редактирования.

Любая помощь будет принята с благодарностью.

Это из журнала, когда я нажимаю кнопка отправки

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)

Я создал 3 страницы редактирования в этой папке views / userprofiles

user_info. html .erb
clinic_info. html .erb
Practitioner_info . html .erb

В своих маршрутах я создал эти маршруты для новых файлов и для обновления

  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"

Я создал этот новый контроллер для этой цели

class UserprofilesController < ApplicationController
# fill the methods as you need, you can always get the user using current_user

def user_info
end

def clinic_info
end

def practitioner_info
end

def update
end

end

Это моя форма для страницы clinic_info

            <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> 

1 Ответ

0 голосов
/ 21 февраля 2020

Ваш метод обновления в UserprofilesController ничего не делает.

Он получает параметры из отправленной формы, но вам также нужно написать код, чтобы что-то с ним сделать (обновление user_profile ).

Это будет выглядеть примерно так:

def update
  if current_user.update(user_params)
    redirect_to #some_path_here
  else
    #do something else if it fails
  end
end

Тогда вам также необходимо определить user_params в приватном разделе, например:

def user_params
  params.require(:user).permit(:clinic_name, :clinic_address, #etc)
end
...