我正在尝试学习如何使用emberjs作为rails api的客户端!
我的代码位于此处:https://github.com/brunoocasali/ember-n-rails
是一个简单的rails-api,它通过restful端点提供CRUD操作。
我正在关注this tutorial,但当我尝试在博文中保存评论时,我收到了Unpermitted params: :post
。
更新01
Started POST "/comments" for 127.0.0.1 at 2015-12-01 10:01:01 -0200
Processing by CommentsController#create as HTML
Parameters: {"comment"=>{"author"=>" asdasdasdas", "body"=>"dasdasd asd asd", "post"=>"1"}}
Completed 500 Internal Server Error in 7ms (ActiveRecord: 0.0ms)
ActiveRecord::AssociationTypeMismatch (Post(#29657520) expected, got String(#11585400)):
app/controllers/comments_controller.rb:13:in `create'
Rendered /home/bruno/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_source.erb (13.1ms)
Rendered /home/bruno/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.7ms)
Rendered /home/bruno/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.5ms)
Rendered /home/bruno/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (43.1ms)
我该如何解决这个问题?
答案 0 :(得分:0)
Unpermitted params: :post
查看此错误,您似乎需要在post
内的强参数定义中允许comments_controller.rb
。所以,试试这个:
private
def comment_params
params.require(:comment).permit(:author, :body, :post)
end