我有以下内容:
class ArticlesController < ApplicationController
before_action :find_article, only: [:edit, :update, :show, :delete]
def create
@article = Article.new
if @article.save(article_params)
flash[:notice] = "Successfully created article!"
redirect_to article_path(@article)
else
flash[:alert] = "Error creating new article!"
render :new
end
end
private
def article_params
params.require(:article).permit(:title, :body)
end
end
日志显示表单正确提交值:
Started POST "/articles" for ::1 at 2017-01-01 11:30:13 -0800
Processing by ArticlesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"xx==", "article"=>{"title"=>"MAKEMEWORK", "body"=>""}, "commit"=>"Create Article"}
(0.3ms) BEGIN
SQL (0.4ms) INSERT INTO "articles" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id" [["created_at", "2017-01-01 19:30:13.630647"], ["updated_at", "2017-01-01 19:30:13.630647"]]
(0.5ms) COMMIT
Redirected to http://localhost:3000/articles/7
Completed 302 Found in 15ms (ActiveRecord: 4.0ms)
但是,在日志中看到的标题值未在控制器中使用。知道为什么吗?