在我的 Rails 博客应用程序中,当我尝试提交新帖子的表单时收到此错误消息:
PostsController#create ActionController::InvalidAuthenticityToken 中的 ActionController::InvalidAuthenticityToken 提取的源代码(在 #211 行附近):
def handle_unverified_request
raise ActionController::InvalidAuthenticityToken
end
end
end
这是我的 posts_controller.rb 文件:
class PostsController < ApplicationController
def index
end
def new
end
def create
@post=Post.new(post_params)
@post.save
redirect_to @post
end
def show
@show=Post.find(params[:id])
end
private
def post_params
params.require(:post).permit(:title,:body)
end
end
这是我的表单代码:
<font color="#BD004B"><h1>New Post<br></h1></font>
<%=form_for :post, url: posts_path do |f|%>
<p>
<%=f.label :title%><br>
<%=f.text_field :title%>
</p>
<p>
<%=f.label :body%><br>
<%=f.text_area :body%>
</p>
<p>
<%=f.submit%>
</p>
<%end%>