我一直在做RoR多年,但这是我第一个使用Mongo(也是我的第一个api-only项目)的项目。我在HABTM协会工作很艰难,我怀疑它与params有关,但我不确定还有什么可以尝试的。Mongoid 6,Rails 5,HABTM“不允许的参数”
下面是我得到了什么:
class Project
include Mongoid::Document
field :name, type: String
field :start_date, type: Date
field :target_date, type: Date
has_and_belongs_to_many :users
end
class User
include Mongoid::Document
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:jwt_authenticatable, jwt_revocation_strategy: JWTBlacklist
field :email, type: String
field :_id, type: String, default: ->{ email }
{ ... devise stuff ...}
has_and_belongs_to_many :projects
end
在我的项目控制,我有这样的参数:
def project_params
params.permit(:id, :name, :start_date, :target_date, :description, user_ids: [])
end
是的,我也试着做{user_ids:[] }。
当我使用Postman进行URL PUT请求以尝试将用户添加到项目时,出现“未经许可的参数”错误。但是...我允许这个参数,对吧?
我有点疯了,因为我不知道我是否有Mongo问题,Rails 5问题或API问题。所有其他呼叫工作正常。
Started PUT "/rapi/projects/3" for 127.0.0.1 at 2017-02-15 22:55:10 -0500
Overwriting existing field _id in class JWTBlacklist.
Overwriting existing field _id in class User.
Processing by Api::V1::ProjectsController#update as JSON
Parameters: {"user_ids"=>"[email protected]", "id"=>"3"}
MONGODB | localhost:27017 | anthem.find | STARTED | {"find"=>"users", "filter"=>{"_id"=>"[email protected]"}}
MONGODB | localhost:27017 | anthem.find | SUCCEEDED | 0.000363703s
Overwriting existing field _id in class Project.
MONGODB | localhost:27017 | anthem.find | STARTED | {"find"=>"projects", "filter"=>{"_id"=>"3"}}
MONGODB | localhost:27017 | anthem.find | SUCCEEDED | 0.000244022s
Unpermitted parameters: user_ids, format
Overwriting existing field _id in class Release.
Completed 204 No Content in 20ms
我很感激任何想法,我还有什么可以尝试。
啊!我的问题不是铁轨问题,而是我真的不知道如何使用邮差。感谢您的回应,解决了它! :) – nilatti