Ruby on rails 带有Atom提要帮助器的嵌套资源
我正在尝试使用为嵌套资源生成提要。我的视图模板(index.atom.builder)是: 我有以下路线:Ruby on rails 带有Atom提要帮助器的嵌套资源,ruby-on-rails,ruby,feed,atom-feed,Ruby On Rails,Ruby,Feed,Atom Feed,我正在尝试使用为嵌套资源生成提要。我的视图模板(index.atom.builder)是: 我有以下路线: map.namespace :public do |pub| pub.resources :users, :has_many => [ :favourites ] pub.resources :favourites pub.resources :assets, :only => [ :show ] end 很遗憾,无法为feed.entry行生
map.namespace :public do |pub|
pub.resources :users, :has_many => [ :favourites ]
pub.resources :favourites
pub.resources :assets, :only => [ :show ]
end
很遗憾,无法为feed.entry行生成url:
feed.entry(favourite, :url => favourite.asset.external_ref) do |entry|
错误为“ActionView::Base的未定义方法'Favorite_url'
我已尝试将feed.entry行更改为:
feed.entry([:public, favourite], :url => favourite.asset.external_ref) do |entry|
但这将返回数组的条目,而不是收藏夹!有人也有类似的问题
我知道增加一行:
map.resource :favourites
到my routes.rb将“修复”此问题,但此资源仅嵌套在/public命名空间下可用
以前有人有过这个问题吗
干杯
Arfon您正在使用
收藏夹.asset.external\u ref
作为条目的标题,这让我相信该条目的URL可能应该定义为:
public_user_favourite_url(:id => favourite, :user_id => @user)
如果favorite.id=9
和@user.id=1
,将生成:
http://localhost:3000/public/users/1/favourites/9
这就是你要找的吗?只是为了跟进。根据Michael的建议,我正在传递完整的url参数,这似乎为feed.entry行生成了正确的url
@favourites.each do |favourite|
feed.entry(favourite, :url => public_user_favourite_url(:id => favourite, :user_id => @user)) do |entry|
entry.title(favourite.asset.external_ref)
entry.content(image_tag(favourite.asset.location), :type => 'html')
entry.author do |author|
author.name(@user.zooniverse_user_id)
end
end
end
嘿,谢谢,成功了!我不确定我怎么会错过这个选项:-)
@favourites.each do |favourite|
feed.entry(favourite, :url => public_user_favourite_url(:id => favourite, :user_id => @user)) do |entry|
entry.title(favourite.asset.external_ref)
entry.content(image_tag(favourite.asset.location), :type => 'html')
entry.author do |author|
author.name(@user.zooniverse_user_id)
end
end
end