简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM