我使用(其中包括):
gem 'rails', '4.0.0'
gem 'sitemap_generator', '3.4'
gem "friendly_id", "~> 5.0.3"
gem 'globalize', '~> 4.0.2'
站点地图生成器应该为我的所有图像创建 url:
class Image < ActiveRecord::Base
attr_accessible :description, :name, :size, :image,
:tag_ids, etc...
has_many :taggings, :dependent => :destroy
has_many :tags, :through => :taggings
has_and_belongs_to_many :articles
mount_uploader :image, ImageUploader
extend FriendlyId
friendly_id :name, use: [:slugged, :history]
translates :name, :description
end
我的站点地图生成器通常运行良好,但不适用于图像模型。相关代码为:
[nil, :de].each do |locale|
Image.find_each do |image|
sitemap.add image_path(image), :changefreq => 'monthly'
end
end
现在,当我 rake sitemap:refresh:no_ping
ActionController::UrlGenerationError: 没有路由匹配 {:action=>"show", :controller=>"images", :locale=>#, :id=>nil, :format=>nil} 缺少必需的键:[:id ]
我想你可能需要更多信息来帮助这里,但我不知道是什么。该网站以两种语言运行良好,rake:routes 提供:
images GET (/:locale)/images(.:format) images#index {:locale=>/en|de/}
POST (/:locale)/images(.:format) images#create {:locale=>/en|de/}
new_image GET (/:locale)/images/new(.:format) images#new {:locale=>/en|de/}
edit_image GET (/:locale)/images/:id/edit(.:format) images#edit {:locale=>/en|de/}
image GET (/:locale)/images/:id(.:format) images#show {:locale=>/en|de/}
PATCH (/:locale)/images/:id(.:format) images#update {:locale=>/en|de/}
PUT (/:locale)/images/:id(.:format) images#update {:locale=>/en|de/}
DELETE (/:locale)/images/:id(.:format) images#destroy {:locale=>/en|de/}
最后我的 routes.rb 是:
scope "(:locale)", locale: /en|de/ do
resources :images do
get 'confirm_destroy', :on => :member
end
end