2010-11-14 54 views
2

這是我在我的模型代碼:Unicode的清潔Rails應用程序URL

def to_param 
    require 'unicode' 
    "#{id}-#{Unicode::normalize_KD("-"+name+"-").downcase.gsub(/[^[:alnum:]]/,'-')}".gsub(/-{2,}/,'-') 
end 

我需要unicode功能,因爲在我的某些條目的名稱,它由口音(外國字符)。沒有unicode它被設置爲用-替換重音字符。

但現在的問題是,它給了我下面的錯誤:

ActionView::TemplateError (no such file to load -- unicode) on line #50 of app/views/spots/index.html.erb: 
47: 
48:    <% @shops.each do |spot| %> 
49:     <div id="<%= dom_id(shop) %>" class="item"> 
50:     <a href="<%= shop_path(shop, :type => @type) %>"> 
51:      <% if !shop.photos.blank? %> 
52:      <%= image_tag(shop.photos.last.url(:thumb), :class => 'thumbnail') %> 
53:      <% else %> 

我該怎麼辦?謝謝。

回答

2

嘗試添加unicode寶石您Gemfile

gem 'unicode' 
+0

我通常會改變我的代碼住在生產,由於與本地機器配置問題的問題。代碼更改後,我通常應用Apache重新啓動。添加完寶石之後,我是否像以前一樣重新啓動Apache以使其生效?謝謝。 – Victor 2010-11-14 16:08:14

+0

因爲我在Passenger上運行Rails應用程序,所以我做了以下安裝gem:'sudo /opt/ruby-enterprise-1.8.7-2010.02/bin/gem install unicode'謝謝。 – Victor 2010-11-14 16:27:40