Routing AJAX request from partials to a specific controller

Hey :slight_smile:

I'm creating this backend administration interface for a very large book database.

I have created, IMHO, a really cool structure of partials that I can reuse in different situations, and offer nested editing of the backend data, like in this little "use case":

- The admin does a search on books and is presented with a tabular list of books with a short description in each row. -=-=- The 'books' controller fetches the data, index.rhtml passes the books array to a partial that renders the list - The admin clicks an entry, and an ajax call is made that replaces the small descriptive table row with a detailed and editable larger presentation of this particular book. -=-=- The book has a property, book.series_participations which is like a list of "memberships" with different series of books. This array attribute is passed directly to a partial, "/ series_participations/backend_table_list", which works in basically exactly the same way as the books partial does, that is, it lists all participations in a nested table which again allows the admin to click and edit a participation directly in the interface without refreshing or redirecting. The same partial is also used directly when listing, searching and editing SeriesParticipation instances, and indirectly (vis-a-vis this book example) in the Series editing module.

So, the series_participation partials will be used by any of three controllers. This is not really any problem until I start using AJAX. Editing, saving, deleting, what have you works fine as long as I always use absolute paths for rendering the partials and as long as I remember to specify the (correct) :controller in the partials. Otherwise, the partials would try to commit etc. to the current controller, e.g. in this example, if editing a series participation opened via the books list, it would try to commit to the :save action on the books controller, which would obviously fail.

Okay, so the problem arises with auto_complete fields in partials that don't "belong" to the current controller. I've already moved auto_complete actions into a dedicated module, so that I can load the ones I need for any one controller without duplicating my code. For instance, there's this one (this is the beginning of my auto_complete_for.rb file):