2013-02-11 65 views
0

这是我的模型无法生成URL

class Tourisme < ActiveRecord::Base 
    has_friendly_id :title, :approximate_ascii => true 

    . 
    . 

end 

当标题包含"?""/",我想生成一个网址:

admin_tourisme_path(tourisme) 

我得到一个错误

admin_tourisme_url failed to generate from {:action=>"show", :id=>#<Tourisme id: 14, title: "title with ?", description:............. 

我该如何解决这个问题

回答

0

所以阅读friendly_id文档(http://rubydoc.info/github/norman/friendly_id/master/file/WhatsNew.md)我发现2个解决方案:

1 - 使用#normalize_friendly_id模型: 从DOC:

再见Babosa

Babosa是FriendlyId 3的猛击库。

FriendlyId 4,因为它最重要的部分已经被接受为主动支持3

但是默认不使用它,Babosa仍然是有用的,例如,对于惯用音译西里尔字母(或其他语言)字符串转换为ASCII。这很容易,包括 - 只需重写#normalize_friendly_id在你的模型:

class MyModel < ActiveRecord::Base 
    ... 

    def normalize_friendly_id(text) 
    text.to_slug.normalize! :transliterations => :russian 
    end 
end 

2 - 使用猛击型号:http://rubydoc.info/github/norman/friendly_id/master/FriendlyId/Slugged