我有两个模型,即会员和公司...... 成员是设计模型......当我注册时,我想在注册表单中包含以下字段。
会员有一家公司
我正在尝试通过嵌套表单创建注册表单。但我不确定为公司构建表单以接收来自用户的输入...
这是我的控制器
class Brands::Members::RegistrationsController < Devise::RegistrationsController
before_action :configure_sign_up_params, only: [:create]
# before_action :configure_account_update_params, only: [:update]
# GET /resource/sign_up
def new
@company = Company.new
super
end
# POST /resource
def create
@company = Company.new(configure_sign_up_params)
@company.valid?
super
end
end
这是我的观点
<h2>Sign up</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name, autofocus: true %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email %>
</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: "off" %>
</div>
<!--
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
-->
<%= @company.errors %>
<%= fields_for @company do |fc| %>
<div class="field">
<%= fc.label :name %><br />
<%= fc.text_field :name %>
</div>
<% end %>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
<%= render "brands/members/shared/links" %>
答案 0 :(得分:1)
希望这会有所帮助,
将您的新操作更改为此
@member = Member.new
@member.build_company