简体   繁体   English

Ruby on Rails-错误的参数数量(0表示1)

[英]Ruby on Rails - Wrong number of arguments (0 for 1)

I created a scaffolded template and get the following error: 我创建了一个脚手架模板,并收到以下错误:

ArgumentError in DuelsController#create wrong number of arguments (0 for 1) DuelsController中的ArgumentError#创建错误数量的参数(0表示1)

Extracted source (around line #74): 提取的源(围绕第74行):

# Never trust parameters from the scary internet, only allow the white list through.
def duel_params
  params.require[:duel].permit(:euro, :authenticity_token)
end
end

Parameters are: 参数为:

{"utf8"=>"✓",
 "authenticity_token"=>"SxksBvZNjPuciScahht76K2fj8r3AWEGe0MGmPfJUfF84GKy8Z2dK8dMGRBRiQ4L1paHUKpdTs6YxUjt6K3nWA==",
 "duel"=>{"euro"=>"5"},
 "commit"=>"Create Duel"}

Code Controller 代码控制器

def create
@duel = Duel.new(duel_params)

respond_to do |format|
  if @duel.save
    format.html { redirect_to @duel, notice: 'Duel was successfully created.' }
    format.json { render :show, status: :created, location: @duel }
  else
    format.html { render :new }
    format.json { render json: @duel.errors, status: :unprocessable_entity }
  end
end

end 结束

# Never trust parameters from the scary internet, only allow the white list through.
def duel_params
  params.require[:duel].permit(:euro, :authenticity_token)
end

Form 形成

 <h1>New Duel</h1>

<%= simple_form_for @duel do |d| %>
  <%= d.input :euro %>
  <%= d.button :submit %>
<% end %>

<%= link_to 'Back', duels_path %>

Where is the bug? 错误在哪里? :/ :/

You should change your duel_params to below 您应该将duel_params更改为以下内容

def duel_params
  params.require(:duel).permit(:euro)
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM