原谅我的无知,但我不仅是Ruby的新品,而且是一般的编程.我正在研究rubyonrails.org边缘指南的例子.并且我收到以下错误,尽管我查看了自应用程序上次工作以来我输入的每一段代码,但我无法修复它.
PostsController中的NoMethodError #create
未定义方法`permit'for {"title"=>"","text"=>""}:ActiveSupport :: HashWithIndifferentAccess
这就是我的posts_controller.rb的样子:
class PostsController < ApplicationController
def new
@post = Post.new
end
def create
@post = Post.new(params[:post].permit(:title, :text))
if @post.save
redirect_to action: :show, id: @post.id
else
render 'new'
end
end
def show
@post = Post.find{params[:id]}
end
def index
@posts = Post.all
end
end
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
预先感谢您的任何帮助!