Merb jQuery

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.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

  • + maraby Matt Todd 2 years ago
    Currently DM doesn’t like to render @proxy_for_array_of_objects.to_json (which display does for us) correctly... it’ll call inspect on each object, so you might end up with something like this: '[#,#,#,...]' which is obviously wrong.
Post a comment
Embed Video
Edit your comment Cancel

6 Favorites

Merb jQuery - Presentation Transcript

  1. Merb with jQuery (not RJS)
  2. Rails and JS
  3. <% remote_form_for(@user) do |f| %> <%= f.text_field :username %> <% end %>
  4. <form action=\"/users\" class=\"new_user\" id=\"new_user\" method=\"post\" onsubmit=\"new Ajax.Request('/users', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\"><div style=\"margin:0;padding: 0\"><input name=\"authenticity_token\" type=\"hidden\" inline JS value=\"dcab4e1ab6a78f1f618b97008246df33340 75ca9\" /></div> <input id=\"user_username\" name=\"user[username]\" size=\"30\" type=\"text\" /> </form>
  5. <center> <font face=\"Arial\">Hello</font> </center>
  6. <center> <font face=\"Arial\">Hello</font> </center> we stopped doing this
  7. “It works”
  8. Kinda.
  9. Difficulty Time in Project
  10. Difficulty remote_form_for... fantastic! so easy! Time in Project
  11. Difficulty autocomplete! wow! I don’t need any JS! Time in Project
  12. holy cow... RJS... Difficulty Who needs this stodgy “Javascript” Time in Project
  13. Difficulty one day... Time in Project
  14. we need an Difficulty autocompleter that talks to a web service Time in Project
  15. Difficulty quick... cancel the launch Time in Project
  16. Difficulty Time in Project
  17. Or...
  18. Difficulty Time in Project
  19. learn JS or hire someone who Difficulty knows JS Time in Project
  20. “It’s hard”
  21. Let’s take a look
  22. <%= form_for(@user, :class => \"remote\", :action => \"/foo\") do %> <%= text_field :username %> <% end =%>
  23. <form class=\"remote\" method=\"post\" action=\"/foo\"> <input type=\"text\" class=\"text\" value=\"\" name=\"username\" id=\"params_username\"/> </form>
  24. And the JavaScript
  25. (scary!)
  26. $(\"form.remote\").ajaxForm();
  27. link_to_remote
  28. <%= link_to_remote \"Awesome!\", :url => \"/foo\", :update => \"some_id\" %>
  29. <a href=\"#\" onclick=\"new Ajax.Updater('some_id', '/foo', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('dcab4e1ab6a78f1f618b97 008246df3334075ca9')}); return false;\">Awesome!</a> JS! inline
  30. <a href=\"#\" onclick=\"new Ajax.Updater('some_id', '/foo', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('dcab4e1ab6a78f1f618b97 008246df3334075ca9')}); return (so easy!) false;\">Awesome!</a>
  31. <%= link_to \"Awesome!\", \"/foo\", :rel => \"#some_id\", :class => \"remote\" %>
  32. <a href=\"/foo\" class=\"remote\" rel=\"#some_id\">Awesome!</a>
  33. “I bet the JavaScript is super-crazy”
  34. $(\"a.remote\").click(function() { if(this.rel) $(this.rel).load(this.href); else $.get(this.href); return false; })
  35. CSS selector $(\"a.remote\").click(function() { if(this.rel) $(this.rel).load(this.href); else $.get(this.href); return false; })
  36. $(\"a.remote\").click(function() { if(this.rel) $(this.rel).load(this.href); else $.get(this.href); return false; }) supplying a rel means update
  37. $(\"a.remote\").click(function() { if(this.rel) $(this.rel).load(this.href); else $.get(this.href); return false; }) otherwise use $.get
  38. X $(\"a.remote\").click(function() { }) if(this.rel) $(this.rel).load(this.href); else $.get(this.href); return false; no JS?
  39. <a href=\"/foo\" class=\"remote\" rel=\"#some_id\">Awesome!</a>
  40. Want a helper?
  41. def link_to_remote(text, url, options = {}) if options.key?(:update) options[:rel] = options.delete(:update) end options[:class] = options[:class].to_s. split(\" \").push(\"remote\").join(\" \") link_to(text, url, options) end
  42. If you switch to Prototype (o.O)
  43. $$(\"a.remote\").observe(\"click\", function() { if(this.rel) new Ajax.Updater($$(this.rel), this.href); else new Ajax.Request(this.href); return false; });
  44. Using JSON
  45. class Speakers < Application provides :json def index @speakers = Speaker.all display @speakers end end
  46. class Speakers < Application provides :json def index @speakers = Speaker.all display @speakers end end
  47. $.getJSON(\"/speakers\", function(json) { // [{id: 1, name: \"Joe Blow\"}] });
  48. $.getJSON(\"/speakers\", function(json) { // [{id: 1, name: \"Joe Blow\"}] }); Accept: application/json
  49. class Speakers < Application provides :json def index @speakers = Speaker.all display @speakers end end @speakers.to_json
  50. What about RJS?
  51. page.insert_html :bottom, 'list', content_tag(\"li\", \"Fox\")
  52. Generated JS
  53. try { new Insertion.Bottom(\"list\", \"<li>Fox</ li>\"); } catch (e) { alert('RJS error:\\n\\n' + e.toString()); alert('new Insertion.Bottom(\\\"list\\\", \\\"<li>Fox</li>\\\");'); throw e }
  54. Big Scary JS
  55. $.get(\"/ajax_url\", function(html) { $(\"#list\").append(html) })
  56. Thank you.

+ Yehuda KatzYehuda Katz, 2 years ago

custom

4371 views, 6 favs, 0 embeds more stats

Using jQuery with Merb (and why Merb doesn't do RJS more

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 4371
    • 4371 on SlideShare
    • 0 from embeds
  • Comments 1
  • Favorites 6
  • Downloads 69
Most viewed embeds

more

All embeds

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