Created
May 23, 2013 00:45
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /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