views:

206

answers:

1

Hi Everyone, I'm using the BaseWithoutTable plugin to extend ActiveRecord. This allows me to create models without underlying tables (I'm getting data from a webservice). I would like my web application to remain restful, however i'm stumped on how to do that without relations.

To be more concrete, let's say I have a book model and an author model and I get both resources from a web service. I would like to access book resources like /authors/1/books.

It seems there could be two routes I could choose. First, hack the relations (belongs_to, has_many) so that I can define my own without the need for foreign keys. Second, I could possibly build custom routes and controller methods that allow me to access the previous url.

If anyone has any thoughts on how to do this I would much appreciate it.

Thanks and let me know if you need more info.

A: 

For the url given you could do the something like the following.

/authors/1/books

class Books < ApplicationController
  before :find_author

  def show
   @books = Books.get_from_web_service_for_author(@author)
  end

  def find_author
    @author = params[:author_id]
  end
end

You would need to define the method for accessing your webservice and also have a nested resource defined in your routes.

MatthewFord