2013-11-17 7 views
0

Это мой код миграции:Невозможно создать псевдоним для has_many: через

1.User

create_table :users do |t| 
     t.string :name 
     t.string :password 
     t.string :department 

     t.timestamps 
    end 

2.Ploy

create_table :ploys do |t| 
     t.string :name 
     t.string :state 
     t.string :description 
     t.string :location 
     t.float :spend 

     t.references :creator, index: true, class_name: "User" 

     t.timestamps 
    end 

3.participants

def change 
    create_table :participants do |t| 
     t.belongs_to :ploy 
     t.belongs_to :user 

     t.timestamps 
    end 

Это мой код модели:

class User < ActiveRecord::Base 
    has_one :create_ploys, class_name: "Ploy" 

    has_many :participants 
    has_many :ploys, through: :participants, source: :join_ploys 
end 

class Ploy < ActiveRecord::Base 
    belongs_to :creator, class_name: "User" 

    has_many :participants 
    has_many :users, through: :participants, source: "joiners" 
end 

class Participant < ActiveRecord::Base 
    belongs_to :user 
    belongs_to :ploy 
end 

Когда я называю user.join_ploys, но дайте мне ошибку: NoMethodError: неопределенный метод `join_ploys'

Так что я думаю, что может быть что-то неправильно о: источник, но я не знаю, как сделать.

ответ

Смежные вопросы