Atom Feed Helper的嵌套资源

我正在尝试使用Rails Atom Feed Helper为嵌套资源生成Feed。 我的视图模板(index.atom.builder)是:

atom_feed(:schema_date => @favourites.first.created_at) do |feed| feed.title("Favourites for #{@user.login}") feed.updated(@favourites.first.created_at) @favourites.each do |favourite| feed.entry(favourite, :url => favourite.asset.external_ref) do |entry| entry.title(favourite.asset.external_ref) entry.content(image_tag(favourite.asset.location), :type => 'html') entry.author do |author| author.name(@user.login) end end end end 

我有以下路线:

  map.namespace :public do |pub| pub.resources :users, :has_many => [ :favourites ] pub.resources :favourites pub.resources :assets, :only => [ :show ] end 

遗憾的是,url无法为feed.entry行生成:

 feed.entry(favourite, :url => favourite.asset.external_ref) do |entry| 

错误是“ActionView :: Base的未定义方法`favourite_url”。

我已经尝试将feed.entry行更改为:

 feed.entry([:public, favourite], :url => favourite.asset.external_ref) do |entry| 

但是这会返回数组的条目而不是最喜欢的条目! 这里也有人有类似的问题。

我知道添加行:

 map.resource :favourites 

到我的routes.rb会’修复’这个问题但是这个资源只能嵌套在/ public命名空间下面。

以前有人有这个问题吗?

干杯Arfon

您正在使用favourite.asset.external_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 param,这似乎为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 
Interesting Posts