Active Resource in Unobtrusive Javascript
I don't know any better way to ask this question than to give my situation.
I have a reader application that needs to be made, on the page it will have the Table of Contents on the left side and the actual content of the book on right. The TOC content shows chapters and sections within the chapter. The content on the right will only shows one of those sections at a time, no preloading the whole book. When you click on the section in the TOC, makes an API call to a separate server that holds all the book data and returns the HTML to be displayed in the content section.
I want to know if there is a way to make the application to use both unobtrusive javascript and active resource. Active resource would handle the interaction between the Rails Application and the server that holds the book content. The unobtrusive javascript would be the controller between the table of contents and the content on the right.
I guess what I'm wondering most of all, beyond just its possibility, is if I can integrate this is such a way that I don't ne开发者_JS百科ed to make unnecessary api calls. Currently, I can't figure out how this would work without it making an api call to rails then making another api call to the book content provider.
Thanks for your help in advance!
@tab
Edit:
The Content model would be used to talk to the external API using ActiveResource. UJS would be used to call that model and display that returned content on the page. So the flow would sort of be like, click link myapp.com/book.js. This would go to the controller book#index that would initialize a variable that gets its data from the content model. The content model would use ActiveResource to make an API call to the external content server and would return html. The html that would be returned would be filtered back out and displayed on the page.
There will certainly be some caching, but the page itself will also need to be dynamic enough to allow editing of the content.
I was able to make a test program that used unobtrusive javascript to call a model using an API call.
It works the exact same as any other unobtrusive javascript setup, but instead the controller makes a call to the activeresource model. It acts no differently, I suppose I shouldn't be surprised.
精彩评论