Ruby on rails Rails-嵌套模型内部设计模型
我有两个模型,分别是会员和公司。。。 成员是设计模型。。。当我注册时,我想在注册表单中包括以下字段Ruby on rails Rails-嵌套模型内部设计模型,ruby-on-rails,ruby-on-rails-3,devise,Ruby On Rails,Ruby On Rails 3,Devise,我有两个模型,分别是会员和公司。。。 成员是设计模型。。。当我注册时,我想在注册表单中包括以下字段 名字 电子邮件地址 密码 公司名称(来自公司模型) 公司类型(来自公司模型) 成员有一家公司 我正在尝试通过嵌套表单创建注册表单。。但我不确定是否要为该公司构建表单以接收用户的输入 这是我的控制器 class Brands::Members::RegistrationsController < Devise::RegistrationsController before_action :
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" %>
注册
(最少字符)
希望这会有所帮助
将您的新操作更改为此
@member = Member.new
@member.build_company