【发布时间】:2020-02-21 06:10:43
【问题描述】:
我正在尝试将我的 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"=>"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 个编辑页面
user_info.html.erb
诊所信息.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>
【问题讨论】:
-
对于多步骤/视图表单,您应该查看 wicked gem github.com/zombocom/wicked
标签: ruby-on-rails routing devise routes