使用Atom Feed助手的嵌套资源 [英] Nested resource with Atom Feed Helper

查看:79
本文介绍了使用Atom Feed助手的嵌套资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use the Rails Atom Feed Helper to generate a feed for a nested resource. My view template (index.atom.builder) is:

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

不幸的是,无法为feed.entry行生成网址:

Unfortunately the url is failing to generate for the feed.entry line:

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

错误是"ActionView :: Base的未定义方法'favourite_url'".

The error is "undefined method `favourite_url' for ActionView::Base".

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

I've tried changing the feed.entry line to:

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

但是这将返回Array而不是收藏夹的条目!有人有类似的问题这里也是.

But this then returns the entry for an Array rather than a favourite! Someone had a similar problem here also.

我知道添加以下行:

map.resource :favourites

到我的route.rb会解决"此问题,但是该资源仅可嵌套在/public名称空间下.

to my routes.rb would 'fix' this problem but this resource is only available nested beneath the /public namespace.

以前有人遇到过这个问题吗?

Has anyone had this problem before?

欢呼 阿方

推荐答案

您正在使用favourite.asset.external_ref作为条目的标题,这使我相信该条目的URL应该定义为:

You are using favourite.asset.external_ref as the title of the entry, which leaves me to believe the URL for that entry should probably be defined as:

public_user_favourite_url(:id => favourite, :user_id => @user)

如果favorite.id = 9@user.id = 1,则会生成:

http://localhost:3000/public/users/1/favourites/9

这是您要寻找的吗?

这篇关于使用Atom Feed助手的嵌套资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆