Reputation: 3285
I am trying to build an API endpoint using active_admin and I am having trouble getting the route set up how I want them. I am also not sure if my solution for the routes is in accordance with REST best practices.
I have the following models:
class Classification < ActiveRecord::Base
end
class Channel < ActiveRecord::Base
belongs_to :classification
has_many :channel_genres
has_many :channel_web_genres
has_many :web_genres, through: :channel_web_genres
end
class ChannelWebGenre < ActiveRecord::Base
belongs_to: channel
belongs_to: web_genre
end
class WebGenre < ActiveRecord::Base
end
I want to create an endpoint that will take the classification_id and the web_genre, and return all of the channels which represent the union between the two(channels that belong to the classification and have the web_genre.) I am brand new to active_admin, and newish to rest best practices so I have the following questions:
1) Which controller/action should this map to from a best practices standpoint. I was leaning toward the web_genre show action nested within classification (GET /classification/:id/web_genre/:id) but it doesn't really feel right to me.
2) Once I determine the controller/action combination how can I nest the resource in active_admin appropriately(Assuming I should be nesting the resource).
If I forgot any information please feel free to comment and I will add it. Thank you in advance for your time and assistance!
Upvotes: 0
Views: 660
Reputation: 3073
In general I'm not sure that ActiveAdmin is the best way to build a API. Take a look onto inherited_resources, wich is used by ActiveAdmin internally by the way.
To your questions:
Upvotes: 2