1

我正在使用friendly_id在我的導軌應用程序上生成URL。嵌套模型中的友好標識

我有以下模型組織:

廣告:

class Ad < ActiveRecord::Base 
belongs_to :area 
... 

地區:

class Area < ActiveRecord::Base 
has_many :ads 
validates :name 
... 

,公元模型下面的函數生成每個廣告的網址:

friendly_id :title_and_title, use: :slugged 

def title_and_title 
"classified ads france #{title}" 
end 

我想要做的是在URL中添加區域名稱。 我怎麼能這樣做?

感謝

回答

2

嘗試:

def title_and_title 
    self.area.name 
end 

要獲取名稱它的父。

+0

def title_and_title 「classified ads france#{title}#{self.area.name}」 end – 2015-01-26 22:47:21