干净的Rails应用程序URL中的Unicode

时间:2010-11-14 14:51:00

标签: ruby-on-rails unicode

这是我模型中的代码:

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 %>

我该怎么办?感谢。

1 个答案:

答案 0 :(得分:2)

尝试将unicode gem添加到Gemfile

gem 'unicode'