Hello,
I am hosting a local server using Ruby on Rails and using Ionic as my frontend.
My home.ts file is as follows:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { BoardPage } from '../board/board';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
boardPage = BoardPage;
boardnames: any;
constructor(public navCtrl: NavController, public http: Http) {
this.http.get('http://localhost:3000/boards/index').map(res => res.json()).subscribe(data => {
console.log(JSON.stringify(data));
this.boardnames = Object.keys(data);
},
err => {
console.log(Object.keys(err));
console.log("Oops!");
});
}
}
The ionic server console prints out that there is an error.
More specifically:
My Rails controller is as follows:
class BoardsController < ApplicationController
def new
end
def create
end
def index
string = '{"boardname":
[{
"board": "name",
"board2": "name2"
}]
}'
render json: JSON.parse(string)
end
end
However, the Ruby server console gives me an HTTP: 200 OK status code, and accessing the site in a web browser gives me this:
My Ionic application works with other websites that provide JSON arrays, however. Just not when I use my local server. So what is going on?