How do I access a user with a specific role in Rails 3?

前端 未结 1 1976
温柔的废话
温柔的废话 2020-12-07 06:26

I have three models for users. User, role & assignments. This is how the models look:

    assignment.rb

# == Schema Information
# Schema version: 201011         


        
相关标签:
1条回答
  • 2020-12-07 06:48

    The question was...given that users (clients) have already been added to a project owned by another user (a designer), how do I retrieve those users

    That is pretty straight forward :

    # Given a project @project = Project.find(id)
    @clients = @project.users.joins(:roles).where("roles.name = 'client'")
    
    0 讨论(0)
提交回复
热议问题