Rails error: ArgumentError in ArticlesController#create wrong number of arguments (2 for 1)
Rails error: ArgumentError in ArticlesController#create wrong number of arguments (2 for 1)
我从这里获得了关于 Rails 的教程:
Rails5
并想在表单中添加一个字段 "attachment"。
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!?
感谢任何帮助!
如上条评论所述:
我将 paperclip 更新到 v5.1.0,错误消失了。
我从这里获得了关于 Rails 的教程: Rails5
并想在表单中添加一个字段 "attachment"。 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!? 感谢任何帮助!
如上条评论所述:
我将 paperclip 更新到 v5.1.0,错误消失了。