更改为_param会在“模型”中产生错误_url

问题描述:

Rails 2.3.8。更改为_param会在“模型”中产生错误_url

下面是我的shop模型to_param

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

当我试图改变#{id}-#{id}/如下:

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

我收到以下错误我index.html.erb

shop_url failed to generate from {:type=>"places", :action=>"show", :controller=>"shops", :id=>#<shop id: 16, shop_type: "fashion", name: "Shop1", shop_subtype: nil, ...} 

Extracted source (around line #54): 

51: 
52:    <% @shops.each do |shop| %> 
53:     <div id="<%= dom_id(shop) %>" class="item"> 
54:     <a href="<%= shop_path(shop, :type => @type) %>"> 
55:      <% if !shop.photos.blank? %> 
56:      <%= image_tag(shop.photos.last.url(:thumb), :class => 'thumbnail') %> 
57:      <% else %> 

我正在尝试将URL从shops/12-shop-abc更改为shops/12/shop-abc。实际上,我实际上正在尝试使用friendly_id更改为shops/shop-abc,但两者均失败。

请帮助。谢谢。

在名称中的.产生正常to_param错误。它已通过friendly_id解决。