ruby-on-rails - Ruby on Rails 参数数量错误(给定 0 预期 1)
问题描述
您好,我正在尝试使用 Ruby on Rails 模型创建新记录,但是我收到了错误的参数错误。
错误信息:
配置/路由.rb
Rails.application.routes.draw do
mount RailsAdmin::Engine => '/admin', as: 'rails_admin' devise_for :modifications devise_for :users 资源 :user_steps 资源 :divorce_steps 资源 :divorces
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'
结尾
离婚控制器.rb:
class DivorcesController < ApplicationController
def new @divorce = Divorce.new 结束
def create @divorce = Divorce.new(user_params) @divorce.save end
私人的
def user_params
params.require.(:divorce).permit(:marriage_date, :seperation_date, :state_of_mariage, :child_support, :address, :childrens_address, :contact_with_other, :telephone)
end
结尾
新的.html.erb
<div class = "container top-cont">
太好了,让我们开始约会吧!
<%= form_with(model: @divorce, local: true) 做 |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)
推荐阅读
- jmeter - 信息 oajeStandardJMeterEngine:线程将继续出错
- r - 在 R 中为对过去几年敏感的面板数据创建虚拟变量
- mysql - MySQL 说:文档 #2054 - 服务器请求客户端未知的身份验证方法
- qt - QtQuick StackView 加载问题
- oracle-sqldeveloper - SQL Developer 未使用我的机器的主机名进行连接
- javascript - 如何从 ip 地址 javascript 等格式中获取最后一位数字?
- android - 自定义相机变焦崩溃(重启)三星手机
- java - 如何在 JAVA 中使用 TypeSafe 从配置中解析地图?
- python - 对于任何索引,返回前两个索引的最小值
- flutter - Flutter:列对齐项目以具有相同的宽度