Ruby on rails 在Rails 4中以嵌套形式更新子对象
我当前的Desive配置有一个用户对象,它有一个表继承结构,可以分解为另外两种用户类型(其中一种是业务)。我试图更新的业务子对象称为“supp_forms”。当我尝试更新记录时,终端中出现以下错误。我正在使用gem的嵌套表单来处理嵌套表单Ruby on rails 在Rails 4中以嵌套形式更新子对象,ruby-on-rails,ruby-on-rails-4,nested-forms,Ruby On Rails,Ruby On Rails 4,Nested Forms,我当前的Desive配置有一个用户对象,它有一个表继承结构,可以分解为另外两种用户类型(其中一种是业务)。我试图更新的业务子对象称为“supp_forms”。当我尝试更新记录时,终端中出现以下错误。我正在使用gem的嵌套表单来处理嵌套表单 Unpermitted parameters: supp_form_attributes 但是,传递的参数看起来是正确的(传递的数据是我在表单中编辑的数据) 我的更新表单如下所示。 business\u profile.html.erb <%= nes
Unpermitted parameters: supp_form_attributes
但是,传递的参数看起来是正确的(传递的数据是我在表单中编辑的数据)
我的更新表单如下所示。
business\u profile.html.erb
<%= nested_form_for @user, url: business_registration_path do |f| %>
<%= f.fields_for :supp_form do |supp_form| %>
<%= supp_form.label :work_phone_number %>
<%= supp_form.text_field :work_phone_number %>
<%= supp_form.label :business_address %>
<%= supp_form.text_field :business_address %>
<%= supp_form.label :business_postal_code %>
<%= supp_form.text_field :business_postal_code %>
<%= supp_form.label :business_city %>
<%= supp_form.text_field :business_city %>
<%= supp_form.label :business_province %>
<%= supp_form.text_field :business_province %>
<%= supp_form.label :employee_count %>
<%= supp_form.text_field :employee_count %>
<% end %>
<%= f.submit %>
<% end %>
class Business < User
# Associations
has_one :supp_form
has_many :loan_applications
has_many :transactions
has_many :listing_information_forms
# Nested attributes
accepts_nested_attributes_for :supp_form
end
class SuppForm < ActiveRecord::Base
# Associations
belongs_to :business
end
class SuppFormsController < ApplicationController
before_filter :authenticate_user!
def edit
@user = User.current_user
end
def update
@user = current_user
@suppform = @user.supp_form
if @suppform.update_attributes(supp_form_params)
business_supp_form_path(@user)
else
render 'edit'
end
end
private
def supp_form_params
params.require(:supp_form).permit(:business_id, :title, :loan_agreement_authorization, :first_name, :last_name, :applicant_role, :work_phone_number, :business_address, :business_postal_code,:business_city, :business_name, :years_in_business, :legal_structure, :ownership, :business_industry, :employee_count, :mobile_phone_number, :business_province, :business_country)
end
end
class BusinessAccountController < ApplicationController
before_filter :authenticate_user!
def business_profile
@user = current_user
end
end
business.rb
<%= nested_form_for @user, url: business_registration_path do |f| %>
<%= f.fields_for :supp_form do |supp_form| %>
<%= supp_form.label :work_phone_number %>
<%= supp_form.text_field :work_phone_number %>
<%= supp_form.label :business_address %>
<%= supp_form.text_field :business_address %>
<%= supp_form.label :business_postal_code %>
<%= supp_form.text_field :business_postal_code %>
<%= supp_form.label :business_city %>
<%= supp_form.text_field :business_city %>
<%= supp_form.label :business_province %>
<%= supp_form.text_field :business_province %>
<%= supp_form.label :employee_count %>
<%= supp_form.text_field :employee_count %>
<% end %>
<%= f.submit %>
<% end %>
class Business < User
# Associations
has_one :supp_form
has_many :loan_applications
has_many :transactions
has_many :listing_information_forms
# Nested attributes
accepts_nested_attributes_for :supp_form
end
class SuppForm < ActiveRecord::Base
# Associations
belongs_to :business
end
class SuppFormsController < ApplicationController
before_filter :authenticate_user!
def edit
@user = User.current_user
end
def update
@user = current_user
@suppform = @user.supp_form
if @suppform.update_attributes(supp_form_params)
business_supp_form_path(@user)
else
render 'edit'
end
end
private
def supp_form_params
params.require(:supp_form).permit(:business_id, :title, :loan_agreement_authorization, :first_name, :last_name, :applicant_role, :work_phone_number, :business_address, :business_postal_code,:business_city, :business_name, :years_in_business, :legal_structure, :ownership, :business_industry, :employee_count, :mobile_phone_number, :business_province, :business_country)
end
end
class BusinessAccountController < ApplicationController
before_filter :authenticate_user!
def business_profile
@user = current_user
end
end
class业务
补充表格rb
<%= nested_form_for @user, url: business_registration_path do |f| %>
<%= f.fields_for :supp_form do |supp_form| %>
<%= supp_form.label :work_phone_number %>
<%= supp_form.text_field :work_phone_number %>
<%= supp_form.label :business_address %>
<%= supp_form.text_field :business_address %>
<%= supp_form.label :business_postal_code %>
<%= supp_form.text_field :business_postal_code %>
<%= supp_form.label :business_city %>
<%= supp_form.text_field :business_city %>
<%= supp_form.label :business_province %>
<%= supp_form.text_field :business_province %>
<%= supp_form.label :employee_count %>
<%= supp_form.text_field :employee_count %>
<% end %>
<%= f.submit %>
<% end %>
class Business < User
# Associations
has_one :supp_form
has_many :loan_applications
has_many :transactions
has_many :listing_information_forms
# Nested attributes
accepts_nested_attributes_for :supp_form
end
class SuppForm < ActiveRecord::Base
# Associations
belongs_to :business
end
class SuppFormsController < ApplicationController
before_filter :authenticate_user!
def edit
@user = User.current_user
end
def update
@user = current_user
@suppform = @user.supp_form
if @suppform.update_attributes(supp_form_params)
business_supp_form_path(@user)
else
render 'edit'
end
end
private
def supp_form_params
params.require(:supp_form).permit(:business_id, :title, :loan_agreement_authorization, :first_name, :last_name, :applicant_role, :work_phone_number, :business_address, :business_postal_code,:business_city, :business_name, :years_in_business, :legal_structure, :ownership, :business_industry, :employee_count, :mobile_phone_number, :business_province, :business_country)
end
end
class BusinessAccountController < ApplicationController
before_filter :authenticate_user!
def business_profile
@user = current_user
end
end
class-SuppForm
支持表单控制器.rb
<%= nested_form_for @user, url: business_registration_path do |f| %>
<%= f.fields_for :supp_form do |supp_form| %>
<%= supp_form.label :work_phone_number %>
<%= supp_form.text_field :work_phone_number %>
<%= supp_form.label :business_address %>
<%= supp_form.text_field :business_address %>
<%= supp_form.label :business_postal_code %>
<%= supp_form.text_field :business_postal_code %>
<%= supp_form.label :business_city %>
<%= supp_form.text_field :business_city %>
<%= supp_form.label :business_province %>
<%= supp_form.text_field :business_province %>
<%= supp_form.label :employee_count %>
<%= supp_form.text_field :employee_count %>
<% end %>
<%= f.submit %>
<% end %>
class Business < User
# Associations
has_one :supp_form
has_many :loan_applications
has_many :transactions
has_many :listing_information_forms
# Nested attributes
accepts_nested_attributes_for :supp_form
end
class SuppForm < ActiveRecord::Base
# Associations
belongs_to :business
end
class SuppFormsController < ApplicationController
before_filter :authenticate_user!
def edit
@user = User.current_user
end
def update
@user = current_user
@suppform = @user.supp_form
if @suppform.update_attributes(supp_form_params)
business_supp_form_path(@user)
else
render 'edit'
end
end
private
def supp_form_params
params.require(:supp_form).permit(:business_id, :title, :loan_agreement_authorization, :first_name, :last_name, :applicant_role, :work_phone_number, :business_address, :business_postal_code,:business_city, :business_name, :years_in_business, :legal_structure, :ownership, :business_industry, :employee_count, :mobile_phone_number, :business_province, :business_country)
end
end
class BusinessAccountController < ApplicationController
before_filter :authenticate_user!
def business_profile
@user = current_user
end
end
类SupplFormsController
业务\账户\控制器.rb
<%= nested_form_for @user, url: business_registration_path do |f| %>
<%= f.fields_for :supp_form do |supp_form| %>
<%= supp_form.label :work_phone_number %>
<%= supp_form.text_field :work_phone_number %>
<%= supp_form.label :business_address %>
<%= supp_form.text_field :business_address %>
<%= supp_form.label :business_postal_code %>
<%= supp_form.text_field :business_postal_code %>
<%= supp_form.label :business_city %>
<%= supp_form.text_field :business_city %>
<%= supp_form.label :business_province %>
<%= supp_form.text_field :business_province %>
<%= supp_form.label :employee_count %>
<%= supp_form.text_field :employee_count %>
<% end %>
<%= f.submit %>
<% end %>
class Business < User
# Associations
has_one :supp_form
has_many :loan_applications
has_many :transactions
has_many :listing_information_forms
# Nested attributes
accepts_nested_attributes_for :supp_form
end
class SuppForm < ActiveRecord::Base
# Associations
belongs_to :business
end
class SuppFormsController < ApplicationController
before_filter :authenticate_user!
def edit
@user = User.current_user
end
def update
@user = current_user
@suppform = @user.supp_form
if @suppform.update_attributes(supp_form_params)
business_supp_form_path(@user)
else
render 'edit'
end
end
private
def supp_form_params
params.require(:supp_form).permit(:business_id, :title, :loan_agreement_authorization, :first_name, :last_name, :applicant_role, :work_phone_number, :business_address, :business_postal_code,:business_city, :business_name, :years_in_business, :legal_structure, :ownership, :business_industry, :employee_count, :mobile_phone_number, :business_province, :business_country)
end
end
class BusinessAccountController < ApplicationController
before_filter :authenticate_user!
def business_profile
@user = current_user
end
end
class BusinessAccountController
注册\u controller.rb(适用于企业)
class Business::RegistrationController
请尝试执行以下操作,它对我方有效,希望对您有所帮助
class RegistrationsController < Devise::RegistrationsController
def create
devise_parameter_sanitizer.for(:sign_up) << { profile_attributes: [:first_name, :last_name] }
super
end
end
类注册控制器 为(:注册)设计参数,其中是许可证(业务:[支持表单属性])
?@МаъСъъъI允许用于创建对象的updateаsanitizedаparams方法中的registrationsаu控制器中的suppаu formаu属性?或者我应该将其放入registrationsаu控制器的update方法中吗?是的,如果需要更新,您应该将其添加到update方法中。