【发布时间】:2016-04-12 14:18:43
【问题描述】:
我有两个模型,成员和公司... 成员是设计模型...当我注册时,我想在注册表单中包含以下字段。
- 姓名
- 电子邮件地址
- 密码
- 公司名称(来自公司模型)
- 公司类型(来自公司模型)
会员拥有一家公司
我正在尝试通过嵌套表单创建注册表单。但我不确定为公司构建表单以接收用户的输入...
这是我的控制器
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" %>
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 devise