将设计编辑表单拆分为多个页面

问题描述 投票:0回答:1

我正在尝试将Rails devise编辑表格分为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"=>"[email protected]", "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个编辑页面

user_info.html.erbclinic_info.html.erb实践者_信息.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

这是我的有关临床信息页面的表格

            <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> 
ruby-on-rails routing devise routes
1个回答
0
投票

您在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
© www.soinside.com 2019 - 2024. All rights reserved.