Ruby on Rails 错误的参数数量(给定 0 期望 1)
Ruby on Rails Wrong Number of arguments (given 0 expected 1)
你好,我正在尝试在 Rails 模型上使用 Ruby 创建新记录,但是我遇到了错误的参数错误。
错误信息:
config/routes.rb
Rails.application.routes.draw do
mount RailsAdmin::Engine => '/admin',如:'rails_admin'
devise_for :修改
devise_for:用户
资源:user_steps
资源:divorce_steps
资源:离婚
root 'nav_pages#home'
get '/home', to:'nav_pages#home'
get '/wwd', to:'nav_pages#wwd'
get '/about', to:'nav_pages#about'
get '/contact', to:'nav_pages#contact'
get '/blog', to:'nav_pages#blog'
get '/are_you_married', to: 'qualifier#are_you_married'
get '/want_a_divorce', to: 'qualifier#want_a_divorce'
结束
divorces_controller.rb:
class DivorcesController < ApplicationController
def 新
@离婚= Divorce.new
结束
定义创建
@divorce = Divorce.new(user_params)
@divorce.save
结束
私人
def user_params
params.require.(:divorce).permit(:marriage_date, :seperation_date, :state_of_mariage, :child_support, :address, :childrens_address, :contact_with_other, :telephone)
end
结束
new.html.erb
<div class = "container top-cont">
太好了,让我们开始约会吧!
<%= form_with(模型:@divorce,本地:真)做|f| %>
<%= f.label :marriage_date %>
<%= f.text_field :marriage_date, class: 'form-control' %>
<%= f.label :seperation_date %>
<%= f.text_field :seperation_date, class: 'form-control' %>
<%= f.label :state_of_marriage %>
<%= f.text_field :state_of_marriage, class: 'form-control' %>
<%= f.label :child_support%>
<%= f.text_field :child_support, class: 'form-control' %>
<%= f.label :child_support %>
<%= f.text_field :child_support, class: 'form-control' %>
<%= f.label :address %>
<%= f.text_field :address, class: 'form-control' %>
<%= f.label :childrens_address %>
<%= f.text_field :childrens_address, class: 'form-control' %>
<%= f.label :contact_with_other %>
<%= f.text_field :contact_with_other, class: 'form-control' %>
<%= f.label :telephone %>
<%= f.text_field :telephone, class: 'form-control' %>
<%= f.submit "Create my account", class: "btn btn-primary" %>
<% end %>
非常感谢任何帮助谢谢!
问题出在divorces_controller.rb
应该是params.require(:divorce)
,不是params.require.(:divorce)
试试:
params.require(:divorce)
实际上强参数使用语法:
params.require(:modal)
你好,我正在尝试在 Rails 模型上使用 Ruby 创建新记录,但是我遇到了错误的参数错误。
错误信息:
config/routes.rb
Rails.application.routes.draw do
mount RailsAdmin::Engine => '/admin',如:'rails_admin' devise_for :修改 devise_for:用户 资源:user_steps 资源:divorce_steps 资源:离婚
root 'nav_pages#home'
get '/home', to:'nav_pages#home'
get '/wwd', to:'nav_pages#wwd'
get '/about', to:'nav_pages#about'
get '/contact', to:'nav_pages#contact'
get '/blog', to:'nav_pages#blog'
get '/are_you_married', to: 'qualifier#are_you_married'
get '/want_a_divorce', to: 'qualifier#want_a_divorce'
结束
divorces_controller.rb:
class DivorcesController < ApplicationController
def 新 @离婚= Divorce.new 结束
定义创建 @divorce = Divorce.new(user_params) @divorce.save 结束
私人
def user_params
params.require.(:divorce).permit(:marriage_date, :seperation_date, :state_of_mariage, :child_support, :address, :childrens_address, :contact_with_other, :telephone)
end
结束
new.html.erb
<div class = "container top-cont">
太好了,让我们开始约会吧!
<%= form_with(模型:@divorce,本地:真)做|f| %>
<%= f.label :marriage_date %>
<%= f.text_field :marriage_date, class: 'form-control' %>
<%= f.label :seperation_date %>
<%= f.text_field :seperation_date, class: 'form-control' %>
<%= f.label :state_of_marriage %>
<%= f.text_field :state_of_marriage, class: 'form-control' %>
<%= f.label :child_support%>
<%= f.text_field :child_support, class: 'form-control' %>
<%= f.label :child_support %>
<%= f.text_field :child_support, class: 'form-control' %>
<%= f.label :address %>
<%= f.text_field :address, class: 'form-control' %>
<%= f.label :childrens_address %>
<%= f.text_field :childrens_address, class: 'form-control' %>
<%= f.label :contact_with_other %>
<%= f.text_field :contact_with_other, class: 'form-control' %>
<%= f.label :telephone %>
<%= f.text_field :telephone, class: 'form-control' %>
<%= f.submit "Create my account", class: "btn btn-primary" %>
<% end %>
非常感谢任何帮助谢谢!
问题出在divorces_controller.rb
应该是params.require(:divorce)
,不是params.require.(:divorce)
试试:
params.require(:divorce)
实际上强参数使用语法:
params.require(:modal)