通过::client\u authorization\u rule
应该是client\u authorization\u rules
class Client < ApplicationRecord
has_many :client_authorization_rules
has_many :projects, through: :client_authorization_rules
end
class Project < ApplicationRecord
has_many :client_authorization_rules
has_many :clients, through: :client_authorization_rules
end
还有一件事作为你写作时的旁注
belongs_to :project
在rails 5中,它自动表示
project_id
保存前需要。所以没有意识到
validates_presence_of :project
class ClientAuthorizationRule < ApplicationRecord
belongs_to :project #it means that project_id required is true
belongs_to :client #it means that client_id required is true
#validates_presence_of :project
#validates_presence_of :client
end