在Ruby on Rails中为关系表设置FriendlyID slug

时间:2016-06-10 04:45:59

标签: ruby-on-rails ruby friendly-url friendly-id

我想从关系表名称设置slug我该怎么办?

例如

Patient Table Info
Id
contact_id
...

Contact Table Info
FirstName - String
LastName - String
...

Patient Model Having below code

extend FriendlyId
friendly_id :full_name, use: :slugged

def full_name
  contact.firstname + '' + contact.lastname
end

但是slug不适用于full_name。所以请帮助我如何帮助我如何使用关系表生成slug?

1 个答案:

答案 0 :(得分:0)

我相信这是因为您的full_name方法。

尝试更改...

def full_name
  contact.firstname + '' + contact.lastname
end

到...

def full_name
  [[self.contact.firstname, self.contact.lastname]]
end