MattiasB
MattiasB

Reputation: 135

Pretty urls (friendly_id gem) with dots

Many solutions are available for rails 2 but none for rails 3.1 because the map object has been removed.

Any solution for this problem in the latest rails?

Upvotes: 0

Views: 745

Answers (1)

Matenia Rossides
Matenia Rossides

Reputation: 1414

I have had to do this recently on a project. Luckily, it's simple to override the slug-generating method on a per-model basis.

please refer to

https://github.com/norman/friendly_id/blob/master/lib/friendly_id/slugged.rb#L113-116

and

https://github.com/norman/friendly_id/blob/master/lib/friendly_id/slugged.rb#L227-231

you should be able to define this on the model:

# Use default slug, but upper case and with underscores
def normalize_friendly_id(string)
  super.upcase.gsub("-", ".")
end

Hope this helps.

Note: This method is available in FriendlyId 3.x as well. It's great for defining a custom regex for generating slug strings.

Upvotes: 2

Related Questions