문제

I currently have a rails app serving up JSON, and a separate app created with phoneJS consuming that JSON. I'd like to be able to integrate the phoneJS code directly into my rails app, but am unsure how. The folder structure for phoneJS is very different to the assets folder in rails. I ideally would like to find an example app where the two are combined, but have been unable to.

도움이 되었습니까?

해결책

I can suggest you to put all phonejs sources to /public folder in your rails application.

For example, I created 'assets' folder into /public and put there my phonejs application.

Next, I made simple home_controller.rb which can return some JSON data.

For retrieving data I was using the following code inside /public/assets/phonejs/views/home.js file:

var data = ko.observableArray();
$.getJSON("/home/index", function(response){
    data(response);
});
var viewModel = {
    data: data
};
return viewModel;

You can see phonejs app at this URL: localhost:3000/assets/phonejs/index.html

Also, you can try to put phonejs sources to vendor/assets or lib/assets or app/assets folder.

Source.zip - source code of my app (ruby 2.0, rails 4).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top