开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜