2

任何人都可以指出如何在处理活动资源关联时添加prefix_option?我也做了以下,但没有成功:执行模型关联时缺少主动资源prefix_option

class League < ActiveResource::Base 
    has_many: teams 
    self.site = "http://api-yyy.com/" 
end 

class Team < ActiveResource::Base 
    belongs_to: league 
    self.site = "http://api-yyy.com/league/:league_id/" 
end 

而在团队控制器,我有:

def index 
    @league = League.find(params[:league_id]) 
    @teams = @league.teams 
end 

但我发现了红宝石:league_id prefix_option当我访问索引页丢失。任何帮助,将不胜感激。

回答

1

我觉得你的活动资源根本应该是

class League < ActiveResource::Base 
 
    has_many: teams 
 
end 
 

 
class Team < ActiveResource::Base 
 
    belongs_to: league 
 
end
您应该使用路线告诉你如何想查看self.site,你应该看看这篇文章,希望这有助于 http://guides.rubyonrails.org/routing.html

+0

@ranjith:那么,你如何设置路线?我目前有浅路线,但我没有找到一种方法来设置路线,并包括self.site ...任何建议? –