【发布时间】:2013-04-19 16:16:09
【问题描述】:
请原谅我的无知,但我不仅对 Ruby,而且对一般编程都是全新的。我正在研究 rubyonrails.org 上关于边缘指南的示例。并且收到以下错误,尽管查看了自应用程序上次运行以来我输入的每一段代码,但我无法修复它。
PostsController#create 中的 NoMethodError
{"title"=>"" 的未定义方法 `permit', "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
我做错了什么?
提前感谢您的帮助!
【问题讨论】:
-
您在控制器操作中获得的
params是ActiveSupport::HashWithIndifferentAccess类的实例,而permit不是该类的实例方法,因此这绝对行不通。你到底想达到什么目的? -
有任何答案解决了您的问题吗?如果有,请将其标记为正确答案。
标签: ruby nomethoderror