我有两个不同的控制器,都继承自ApplicationController和。class PagesController < ApplicationControllerclass CommentsController < ApplicationController
发布时page#test将所有发布的参数复制到另一个哈希属性:
# POST '/pages/test' :
{ "awd":"awd" }
# result :
{
"awd": "awd",
"action": "test_post",
"controller": "pages",
"page": {
"awd": "awd"
}
}
# POST '/comments' :
{"awd":"awd"}
# result :
{
"awd": "awd",
"action": "create",
"controller": "comments",
"comment": {}
}
评论路线由创建resources :comments, only: [:create],post '/comments' => 'comments#create'做同样的事情。
PS:before_filter其中任何一个都没有或任何额外的代码,所有请求都是 json,wrap_parameter.rb有wrap_parameters format: [:json].
编辑
这些控制器之间只有一个区别,CommentsController生成的rails g scaffold ...和PagesController生成的rails g controller ...
编辑 2
self._wrapper_optionsinCommentsController self._wrapper_options的值为
{
"format": [
"json"
],
"include": [
"_id",
"created_at",
"updated_at",
"content",
],
"name": "comment"
}
这造成了问题,但是为什么当我没有在 wrap_parameters 中设置包含时,rails 添加了那个?