簡體   English   中英

Ruby on Rails-錯誤的參數數量(0表示1)

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

我創建了一個腳手架模板,並收到以下錯誤:

DuelsController中的ArgumentError#創建錯誤數量的參數(0表示1)

提取的源(圍繞第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

參數為:

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

代碼控制器

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

結束

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

形成

 <h1>New Duel</h1>

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

<%= link_to 'Back', duels_path %>

錯誤在哪里? :/

您應該將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