我有以下嵌套资源:
resources :categories, :only => [:show], :path => "" do
resources :games, :only => [:show], :path => "" do
end
要检索我所做的所有项目:
@feeditems = Game.all(:include => [:categorygames => :category])
要在.erb模板中显示它们:
<%= category_game_path(feeditem.categorygames.first.category, feeditem) %>
到目前为止,此工作正常。现在我想用同样的方法在网址中加入网址 原子进料。我必须指定网址,所以我做了以下内容:
@feeditems.each do |feeditem|
feed.entry(feeditem, :url => category_game_path(feeditem.categorygames.first.category, feeditem)) do |entry|
entry.title feeditem.name_de
...
不幸的是我总是得到一个“NoMethodError”-Error,并且“未定义的方法`category_game__path'#&lt;#:0x007fa7c96c3090&gt;”
为什么构建器的行为与.erb-template不同?任何想法,如何解决这个问题?
修改
我更进了一步,因为someone else有类似的问题。
我把它更改为:
feed.entry(:url => url_for(:action => 'show', :controller =>'games', :category_id => feeditem.categorygames.first.category, :id => feeditem, :only_path => false)) do |entry|
现在我收到了这个错误:
undefined method `id' for {:url=>"http://localhost:3000/sport-games/wizard-game"}:Hash
尽管如此,我还是没有想法,所以解决这个问题。
答案 0 :(得分:1)
我不知道为什么,但在重新启动服务器和冷重装后,它会以这种方式工作:
feed.entry(feeditem, :url => url_for(:action =>'show', :controller =>'games',:category_id => feeditem.categorygames.first.category, :id => feeditem, :only_path => false)) do |entry|