ruby-on-rails 我在一个rails应用程序中使用了一个devise生成的视图,我的name字段总是得到nil

92dk7w1h  于 2023-06-07  发布在  Ruby
关注(0)|答案(1)|浏览(134)

这个视图是用devise生成的。emailpassword字段工作正常,但name字段返回nil

<h2>Sign up</h2>

<%# This is for an 'organisation' model so I think the problem could be somewhere here %>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
  <%= render "devise/shared/error_messages", resource: resource %>

  <div class="field">
    <%= f.label :email %><br />
    <%= f.email_field :email, autofocus: true, autocomplete: "email" %>
  </div>

  <div class="field">
    <%# The issue is here  %>
    <%= f.label :name %><br />
    <%= f.text_field :name, autofocus: true %>
  </div>

  <div class="field">
    <%= f.label :password %>
    <% if @minimum_password_length %>
    <em>(<%= @minimum_password_length %> characters minimum)</em>
    <% end %><br />
    <%= f.password_field :password, autocomplete: "new-password" %>
  </div>

  <div class="field">
    <%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation, autocomplete: "new-password" %>
  </div>

  <div class="actions">
    <%= f.submit "Sign up" %>
  </div>
<% end %>

<%= render "devise/shared/links" %>
0kjbasz6

0kjbasz61#

将resource替换为_for行中的resource_name:

<%= form_for(resource_name, resource, as: resource_name, url: registration_path(resource_name)) do |f| %>

相关问题