jeudi 21 janvier 2016

RAILS how to get projects from the projectmemberships model into the jBUILDER file

i am making an api. i have 3 models the users the projects and the projectmemberships with associations of:

user.rb

  1. has_many :projects, dependent: :destroy
  2. has_many :projectmemberships
  3. has_many :membered_projectmemberships, :class_name => "projectmemberships", :foreign_key => "project_id"
  4. has_many :membered_projects, :through => :membered_projectmemberships, :source => :project

project.rb

  1. belongs_to :user
  2. has_many :pmembers, :through => :projectmemberships

projectmembership.rb

  1. belongs_to :user
  2. belongs_to :project, :class_name => "Project"
  3. belongs_to :pmember, :class_name => "User"

i could get users membered to a project through the pmembers in the show.jbuilder

json.pmembers @project.pmembers, :id,:name

but now i dont know how to get the projects the users is membered to i try to follow the tutorial of http://ift.tt/1riQTaC

but i get is a uninitialized constant User::projectmemberships

when i try json.membered_projects @user.membered_projects, :id, :name

Aucun commentaire:

Enregistrer un commentaire