2017-09-14 74 views
0

我對Rails很新,所以請耐心等待。用戶可以有很多導師,導師所屬的用戶從其他表訪問屬性

class User < ApplicationRecord 
    # Include default devise modules. Others available are: 
    # :confirmable, :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable, 
     :confirmable, :omniauthable 

    validates :firstname, :lastname, presence: true 
    has_many :mentors 


class Mentor < ApplicationRecord 
    belongs_to :user 
    has_many :photos 

我需要的導師顯示頁面中使用的用戶名。有人能告訴我該怎麼辦?正如我之前所說的,我對Rails很陌生。所以如果有人能告訴我我需要做的分步改變,那會非常有幫助。

+0

https://apidock.com/rails/Module/delegate –

回答

1

如果您在MentorsController#show定義@mentor

"#{@mentor.user.firstname} #{@mentor.user.lastname}" 
+0

它的工作! !非常感謝! – Lily

+0

你知道我怎麼能把一個導師屬性拉到相關的用戶展示頁面?謝謝。 – Lily