Unicode in clean Rails app URL
This is my code in my model:
def to_param
require 'unicode'
"#{id}-#{Unicode::normalize_KD("-"+name+"-").downcase.gsub(/[^[:alnum:]]/,'-')}".gsub(/-{2,}/,'-')
end
I needed the unicode
feature because in the name of my certain entries, it consists of accent (foreign characters). Without the unicode
it was set to replace the accent character with a -
.
But the problem right now is it gives me the following error:
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 %>
What should I do? Thanks.
Try adding the unicode
gem to your Gemfile
:
gem 'unicode'
精彩评论