Skip to content

Instantly share code, notes, and snippets.

@draffauf
Created May 23, 2013 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save draffauf/5632023 to your computer and use it in GitHub Desktop.
Save draffauf/5632023 to your computer and use it in GitHub Desktop.
I was having trouble munging JSON data from a Rails API into a format that Ember would accept. This is what worked for me. I also used the active_model_serializers gem, but I think it was unnecessary for this simple example.
# /app/controllers/api/v1/articles_controller.rb
# ...
def index
@articles = Article.all
respond_to do |format|
format.json { render json: @articles, :callback => params[:callback] }
end
end
# ...
# In EmberJS
# source = "http://localhost:3000/api/v1/articles.json?callback=?"
# => jQuery1910899980530841276_1369269371244({"articles":[{"title":"Article","body":"Lorem"},{"title":"Post","body":"Praesent"}]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment