Rails 2.3.8。
以下是to_param
模型中的shop
:
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 %>
我正在尝试将网址从shops/12-shop-abc
更改为shops/12/shop-abc
。事实上,我实际上是尝试使用friendly_id更改为shops/shop-abc
,但它在两者上都失败了。
请帮忙。感谢。
答案 0 :(得分:0)
名称中的.
会产生正常to_param
的错误。它是用friendly_id解决的。