Javascript REST with Jester

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    3 Favorites & 3 Groups

    Javascript REST with Jester - Presentation Transcript

    1. Javascript REST with Jester
    2. mikebailey mike@bailey.net.au deprec awesome new client Rails app launching soon available for interesting work
    3. the problem • gmap based content management app • didn’t want to reload page • wanted to keep controller simple
    4. enter the jester • http://giantrobots.thoughtbot.com/ • jester.js => 657 lines of javascript • javascript access to your models via REST
    5. How much work does it take to implement?
    6. Not much!
    7. <%= javascript_include_tag :defaults %> <%= javascript_include_tag 'jester.js' %> <%= javascript_include_tag 'demo.js' %>
    8. // demo.js // Object definitions Base.model('PaperRound'); Base.model('Property'); Base.model('Subscription');
    9. Javascript REST in 60 seconds
    10. # Create our application rails demo cd demo/ ./script/generate scaffold_resource Property name:string address:string ./script/generate scaffold_resource PaperRound name:string ./script/generate scaffold_resource Subscription paper_round_id:integer property_id:integer position:integer # Setup our database mysqladmin -u root drop demo_development mysqladmin -u root create demo_development rake db:migrate
    11. # put in some static content rm app/views/layouts/* public/index.html echo ' <html><head></head><body> <%= [:properties, :paper_rounds, :subscriptions].collect {|i| link_to(i, send(\"#{i}_path\"))}.join(\" | \") %> <%= yield %> <%= javascript_include_tag :defaults %> <%= javascript_include_tag \"jester.js\" %> <%= javascript_include_tag \"demo.js\" %> </body></html> ' > app/views/layouts/application.rhtml echo “ Base.model('PaperRound'); Base.model('Property'); Base.model('Subscription'); ” > public/javascripts/demo.js cp ~/jester.js public/javascripts/
    12. # Let's go! ./script/server open http://localhost:3000/properties
    13. • interactive javascript console
    14. # new # note, reflection available but not turned on by default # rails patch by jesters author has been accepted into core property = Property.build( {name: 'Kevin', address: '40 The Avenue, Windsor'} ); property.id; # => null property.save(); property.id; # => 4
    15. # create property = Property.create( {name: 'Kim', address: 'Meadowvale'} ); property.id;
    16. # index properties = Property.find('all'); properties.pluck('name');
    17. # show property = Property.find(2); alert('address = ' + property.address);
    18. # update property = Property.find(1); property.address = 'Ridgecrest Retirement Village'; property.save();
    19. # destroy Property.find('all').last().destroy();
    20. # reload a model property.reload(); # can cause problems if your object has associations # as it recreates objects - existing references to # the associated objects are orphaned
    21. Associations
    22. class PropertyController < ApplicationController # GET /properties # GET /properties.xml def index respond_to do |format| format.html # index.rhtml format.xml { render :xml => @properties.to_xml( :include => [:subscriptions], # associated models :methods => [:amount_owing] # call these methods ) } end end
    23. Other Tips Use Rails’s .to_xml, not .to_json Changeset 7156 Patch in core for .to_xml clash between :include & :methods
    24. more info • jester is documented in three blog posts • http://giantrobots.thoughtbot.com/ • I’ve linked to them on my blog • http://mike.bailey.net.au/blog/?p=15

    + mbaileymbailey, 3 years ago

    custom

    2912 views, 3 favs, 5 embeds more stats

    Mike Bailey gave a presentation on a Javascript lib more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 2912
      • 2755 on SlideShare
      • 157 from embeds
    • Comments 0
    • Favorites 3
    • Downloads 57
    Most viewed embeds
    • 149 views on http://mike.bailey.net.au
    • 5 views on http://www.deprecated.org
    • 1 views on http://honyaku.yahoofs.jp
    • 1 views on http://www.bailey.net.au
    • 1 views on applewebdata://24F976E2-6613-4CDB-89C5-A41536C2D01B

    more

    All embeds
    • 149 views on http://mike.bailey.net.au
    • 5 views on http://www.deprecated.org
    • 1 views on http://honyaku.yahoofs.jp
    • 1 views on http://www.bailey.net.au
    • 1 views on applewebdata://24F976E2-6613-4CDB-89C5-A41536C2D01B

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories