新手问题 stringify_keys 错误?

Unknow user · May 27, 2013 · Last by yehualiu replied at May 29, 2013 · 2322 hits

NoMethodError in CommitsController#create

undefined method `stringify_keys' for "Create Commit":String

def create @post = Post.find(params[:post_id]) @post.commits = @post.commits.create(params[:commit]) redirect_to @post end

谢谢 !!!

params[:commit] 是个 hash 么?不是的话就需要 类似这样的 @post.commits.create(commit: params[:commit])

Unknow user #1 May 27, 2013

还是没有解决哈,谢谢你了哈

@post.commits << @post.commits.create(params[:commit])

试试。

Unknow user #3 May 27, 2013

@jjzxcc还是没有解决哈,谢谢你了哈

#2 楼 @yehualiu 在 controller 里 create 前下个 debugger 然后进 irb 调试下... 先确定 params[:commit] 的类型 必须是 hash 然后确定@post.commits是不是 Commit 类型的 relation 这个错误排查不困难的 撸主加勒个油

Unknow user #5 May 28, 2013

OK,thank you!

Unknow user #6 May 29, 2013

版本的问题,我换了 3.2.12 就行了

Unknow user #7 May 29, 2013

thank you all

You need to Sign in before reply, if you don't have an account, please Sign up first.