0

I want to set slug from relationship table name How can I?

For example

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

but slug is not working for full_name. So help any one help me how can I generate slug with relationship table?

Dipak Panchal
  • 5,996
  • 4
  • 32
  • 68
  • How is your relationship defined between Patient and Contact? Can you add the belongs_to / has_one (or whatever you have) from your model to the question? Thanks. – Matouš Borák Jun 10 '16 at 05:35
  • Also, have a look at [this question](http://stackoverflow.com/questions/11488700/friendly-id-using-value-from-belongs-to-association), it seems to be equivalent to yours. – Matouš Borák Jun 10 '16 at 05:40

1 Answers1

0

I believe that it is because of your full_name method.

Try changing...

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

to...

def full_name
  [[self.contact.firstname, self.contact.lastname]]
end
Beengie
  • 1,588
  • 4
  • 18
  • 36