Question

I'm going to use Emberjs to an existing Rails app and itt have already some scaffold resources.

In this guide I've read that is better to create a path like: "/api/posts" to handle request for emberjs. But I know that Rails responds to JSON if I pass ".json" to my url: e.g.; /posts.json

So, should I create a /api or I could use my default controller to handle JSON? which is the better choise? If I use default controller i'll use something like

 def index
    @posts = Post.find(:all)

    respond_to do |format|
      format.html
      format.json { render :json => @posts.to_json }
    end
  end
Was it helpful?

Solution

One possible solution might be to hook into the buildURL function of your RESTAdapter and adding the .json suffix yourself. This could look something like this:

App.Adapter = DS.RESTAdapter.extend({
  buildURL: function(record, suffix) {
    var url = this._super(record, suffix);
    return url + ".json";
  }
})

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top