Rails错误:ArticlesController中的ArgumentError#创建错误的参数个数(2个为1)

时间:2017-01-11 16:01:35

标签: ruby-on-rails-5

我从这里有Rails教程: Rails5

并希望在表单中添加字段“附件”。 articles_controller.rb如下:

class ArticlesController < ApplicationController

http_basic_authenticate_with name: "gerrit", password: "Ifb6K54WVs7U", except: [:index, :show]

def index
  @articles = Article.all
end

def show
  @article = Article.find(params[:id])
end



def new
  @article = Article.new
end

def edit
  @article = Article.find(params[:id])
end

def create
  @article = Article.new(article_params)

  if @article.save
    redirect_to @article
  else
    render 'new'
  end
end

def update
  @article = Article.find(params[:id])

  if @article.update(article_params)
    redirect_to @article
  else
    render 'edit'
  end
end

def destroy
  @article = Article.find(params[:id])
  @article.destroy

  redirect_to articles_path
end

private
  def article_params
    params.require(:article).permit(:title, :text, :attachment)
  end
end

为此我添加了回形针和turbolink5。

我重新运行教程中的所有配置步骤,但我总是在标题中收到错误:

  Extracted source (around line #24):

def create
  @article = Article.new(article_params)

  if @article.save
    redirect_to @article

我这里不使用单个参数,但是article_params!? 任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:0)

正如上一篇评论所说:

我将回形针更新到v5.1.0,错误消失了。