Rafiki Assumani
Rafiki Assumani

Reputation: 41

Activeresource prefix_option missing when doing models association

Can anyone point me to how to add the prefix_option when dealing with active resource association? I have done the following but with no success:

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

And in the Team controller, I have :

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

But I'm getting ruby :league_id prefix_option missing when I visit the index page. Any help would be appreciated.

Upvotes: 2

Views: 891

Answers (1)

akhil ranjith
akhil ranjith

Reputation: 72

I think your active resource simply should be

class League < ActiveResource::Base
   has_many: teams
end

 class Team < ActiveResource::Base
   belongs_to: league
 end
You should use routes to show how you want to view self.site , you should take a look at this article hope this helps http://guides.rubyonrails.org/routing.html

Upvotes: 1

Related Questions