簡體   English   中英

Ruby on Rails 參數數量錯誤(假設為 0,預期為 1)

[英]Ruby on Rails Wrong Number of arguments (given 0 expected 1)

你好,我正在嘗試使用 Ruby on Rails 模型創建一個新記錄,但是我收到了一個錯誤的參數錯誤。

錯誤信息:

在此處輸入圖片說明

配置/路由.rb

Rails.application.routes.draw do

mount RailsAdmin::Engine => '/admin', as: 'rails_admin' devise_for :modifications devise_for :users resources :user_steps resources :divorce_steps resources :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'

結尾

離婚_controller.rb:

class DivorcesController < ApplicationController

def new @divorce = Divorce.new end

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) do |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) 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM