ironsand
ironsand

Reputation: 15151

Is there way to use friendly_id for not unique value

I'm writing a rails project that is about stock market. There is a ticker symbol that represent a company. e.g. "AAPL" for Apple.

But the ticker symbol is only unique for current listed companies, the symbols are duplicated when delisted companies are included. And I want to include also delisted companies to the system.

Currently I'm thinking to create two columns for ticker symbols like ticker and ticker_for_friendly_id. And only currently existing companies have both values and delisted companies only have ticker values.

But to save same value in two columns are bit redundant, is there a better way to implement it situation like this?

Upvotes: 0

Views: 71

Answers (1)

penner
penner

Reputation: 2737

friendly_id :slug_candidates, use: :slugged

def slug_candidates
  [
    :ticker_slug
  ]
end

def ticker_slug
  str = ticker
  str += '-unlisted' if unlisted?
end

Upvotes: 2

Related Questions