SlideShare une entreprise Scribd logo
1  sur  56
Télécharger pour lire hors ligne
Merb with jQuery
(not RJS)
Rails and JS
<% remote_form_for(@user) do |f| %>
  <%= f.text_field :username %>
<% end %>
<form action=quot;/usersquot; class=quot;new_userquot;
id=quot;new_userquot; method=quot;postquot; onsubmit=quot;new
Ajax.Request('/users', {asynchronous:true,
evalScripts:true,
parameters:Form.serialize(this)}); return
false;quot;><div style=quot;margin:0;padding:
0quot;><input name=quot;authenticity_tokenquot;
type=quot;hiddenquot;
               inline JS
value=quot;dcab4e1ab6a78f1f618b97008246df33340
75ca9quot; /></div>
  <input id=quot;user_usernamequot;
name=quot;user[username]quot; size=quot;30quot;
type=quot;textquot; />
</form>
<center>
  <font face=quot;Arialquot;>Hello</font>
</center>
<center>
  <font face=quot;Arialquot;>Hello</font>
</center>
              we stopped
              doing this
“It works”
Kinda.
Difficulty




           Time in Project
Difficulty remote_form_for...
      fantastic! so easy!



               Time in Project
Difficulty  autocomplete!
         wow! I don’t need
             any JS!


               Time in Project
holy cow... RJS...
Difficulty
       Who needs this stodgy
            “Javascript”



              Time in Project
Difficulty

           one day...



             Time in Project
we need an
Difficulty
    autocompleter that talks
         to a web service



              Time in Project
Difficulty   quick... cancel
            the launch



                Time in Project
Difficulty




           Time in Project
Or...
Difficulty




           Time in Project
learn JS or
    hire someone who
Difficulty knows JS




             Time in Project
“It’s hard”
Let’s take a look
<%= form_for(@user, :class => quot;remotequot;, :action => quot;/fooquot;) do %>
  <%= text_field :username %>
<% end =%>
<form class=quot;remotequot; method=quot;postquot; action=quot;/fooquot;>
  <input type=quot;textquot; class=quot;textquot; value=quot;quot; name=quot;usernamequot; id=quot;params_usernamequot;/>
</form>
And the JavaScript
(scary!)
$(quot;form.remotequot;).ajaxForm();
link_to_remote
<%= link_to_remote quot;Awesome!quot;,
    :url => quot;/fooquot;,
    :update => quot;some_idquot; %>
<a href=quot;#quot; onclick=quot;new
Ajax.Updater('some_id', '/foo',
{asynchronous:true, evalScripts:true,
parameters:'authenticity_token=' +
encodeURIComponent('dcab4e1ab6a78f1f618b97
008246df3334075ca9')}); return
false;quot;>Awesome!</a> JS!
              inline
<a href=quot;#quot; onclick=quot;new
Ajax.Updater('some_id', '/foo',
{asynchronous:true, evalScripts:true,
parameters:'authenticity_token=' +
encodeURIComponent('dcab4e1ab6a78f1f618b97
008246df3334075ca9')}); return
              (so easy!)
false;quot;>Awesome!</a>
<%= link_to quot;Awesome!quot;, quot;/fooquot;,
    :rel => quot;#some_idquot;,
    :class => quot;remotequot; %>
<a href=quot;/fooquot; class=quot;remotequot; rel=quot;#some_idquot;>Awesome!</a>
“I bet the JavaScript is super-crazy”
$(quot;a.remotequot;).click(function() {
   if(this.rel) $(this.rel).load(this.href);
   else $.get(this.href);
   return false;
})
CSS selector


$(quot;a.remotequot;).click(function() {
   if(this.rel) $(this.rel).load(this.href);
   else $.get(this.href);
   return false;
})
$(quot;a.remotequot;).click(function() {
   if(this.rel) $(this.rel).load(this.href);
   else $.get(this.href);
   return false;
})

     supplying a rel
     means update
$(quot;a.remotequot;).click(function() {
   if(this.rel) $(this.rel).load(this.href);
   else $.get(this.href);
   return false;
})
    otherwise
    use $.get
X
$(quot;a.remotequot;).click(function() {



})
   if(this.rel) $(this.rel).load(this.href);
   else $.get(this.href);
   return false;




            no JS?
<a href=quot;/fooquot; class=quot;remotequot; rel=quot;#some_idquot;>Awesome!</a>
Want a helper?
def link_to_remote(text, url, options = {})
  if options.key?(:update)
    options[:rel] = options.delete(:update)
  end

  options[:class] = options[:class].to_s.
    split(quot; quot;).push(quot;remotequot;).join(quot; quot;)

  link_to(text, url, options)
end
If you switch to Prototype (o.O)
$$(quot;a.remotequot;).observe(quot;clickquot;, function() {
  if(this.rel) new Ajax.Updater($$(this.rel), this.href);
  else new Ajax.Request(this.href);
  return false;
});
Using JSON
class Speakers < Application
  provides :json

  def index
    @speakers = Speaker.all
    display @speakers
  end

end
class Speakers < Application
  provides :json

  def index
    @speakers = Speaker.all
    display @speakers
  end

end
$.getJSON(quot;/speakersquot;, function(json) {
  // [{id: 1, name: quot;Joe Blowquot;}]
});
$.getJSON(quot;/speakersquot;, function(json) {
  // [{id: 1, name: quot;Joe Blowquot;}]
});
      Accept:
 application/json
class Speakers < Application
  provides :json

  def index
    @speakers = Speaker.all
    display @speakers
  end

end    @speakers.to_json
What about RJS?
page.insert_html :bottom, 'list',
                 content_tag(quot;liquot;, quot;Foxquot;)
Generated JS
try {
  new Insertion.Bottom(quot;listquot;, quot;<li>Fox</
li>quot;);
} catch (e) {
  alert('RJS error:nn' + e.toString());
alert('new Insertion.Bottom(quot;listquot;,
quot;<li>Fox</li>quot;);');
  throw e
}
Big Scary JS
$.get(quot;/ajax_urlquot;, function(html) {
   $(quot;#listquot;).append(html)
})
Thank you.

Contenu connexe

Tendances

WordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin PagesWordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin Pages
Brandon Dove
 

Tendances (20)

jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
22 j query1
22 j query122 j query1
22 j query1
 
WordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin PagesWordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin Pages
 
Devoxx 2014-webComponents
Devoxx 2014-webComponentsDevoxx 2014-webComponents
Devoxx 2014-webComponents
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
DOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQueryDOM Scripting Toolkit - jQuery
DOM Scripting Toolkit - jQuery
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
 
jQuery
jQueryjQuery
jQuery
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgets
 
KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7
 
JQuery in Seaside
JQuery in SeasideJQuery in Seaside
JQuery in Seaside
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 
Introduction to JQuery
Introduction to JQueryIntroduction to JQuery
Introduction to JQuery
 
Telling Stories With RSpec
Telling Stories With RSpecTelling Stories With RSpec
Telling Stories With RSpec
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery Essentials
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Introduction to Prototype JS Framework
Introduction to Prototype JS FrameworkIntroduction to Prototype JS Framework
Introduction to Prototype JS Framework
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
Web Projects: From Theory To Practice
Web Projects: From Theory To PracticeWeb Projects: From Theory To Practice
Web Projects: From Theory To Practice
 

En vedette

Merb Day Keynote
Merb Day KeynoteMerb Day Keynote
Merb Day Keynote
Yehuda Katz
 
Vaporware To Awesome
Vaporware To AwesomeVaporware To Awesome
Vaporware To Awesome
Yehuda Katz
 
Why You Shouldn't Write OO
Why You Shouldn't Write OO Why You Shouldn't Write OO
Why You Shouldn't Write OO
Yehuda Katz
 
Making your oss project more like rails
Making your oss project more like railsMaking your oss project more like rails
Making your oss project more like rails
Yehuda Katz
 

En vedette (6)

Merb Day Keynote
Merb Day KeynoteMerb Day Keynote
Merb Day Keynote
 
Appnovation One Sheet
Appnovation One SheetAppnovation One Sheet
Appnovation One Sheet
 
Vaporware To Awesome
Vaporware To AwesomeVaporware To Awesome
Vaporware To Awesome
 
Testing Merb
Testing MerbTesting Merb
Testing Merb
 
Why You Shouldn't Write OO
Why You Shouldn't Write OO Why You Shouldn't Write OO
Why You Shouldn't Write OO
 
Making your oss project more like rails
Making your oss project more like railsMaking your oss project more like rails
Making your oss project more like rails
 

Similaire à Merb jQuery

Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
Wen-Tien Chang
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentation
railsconf
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
Carles Farré
 
Html and i_phone_mobile-2
Html and i_phone_mobile-2Html and i_phone_mobile-2
Html and i_phone_mobile-2
tonvanbart
 
Solr and symfony in Harmony with SolrJs
Solr and symfony in Harmony with SolrJsSolr and symfony in Harmony with SolrJs
Solr and symfony in Harmony with SolrJs
Wildan Maulana
 

Similaire à Merb jQuery (20)

Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentation
 
JavaScript on Rails 튜토리얼
JavaScript on Rails 튜토리얼JavaScript on Rails 튜토리얼
JavaScript on Rails 튜토리얼
 
Page Caching Resurrected
Page Caching ResurrectedPage Caching Resurrected
Page Caching Resurrected
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax components
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
 
Html and i_phone_mobile-2
Html and i_phone_mobile-2Html and i_phone_mobile-2
Html and i_phone_mobile-2
 
Solr and symfony in Harmony with SolrJs
Solr and symfony in Harmony with SolrJsSolr and symfony in Harmony with SolrJs
Solr and symfony in Harmony with SolrJs
 
Front End on Rails
Front End on RailsFront End on Rails
Front End on Rails
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone Interactivity
 
Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008
 
jQuery for Sharepoint Dev
jQuery for Sharepoint DevjQuery for Sharepoint Dev
jQuery for Sharepoint Dev
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 
Django - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosDjango - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazos
 
Boston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsBoston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on Rails
 
Jsf Ajax
Jsf AjaxJsf Ajax
Jsf Ajax
 
Struts2
Struts2Struts2
Struts2
 
Opensocial Codelab
Opensocial CodelabOpensocial Codelab
Opensocial Codelab
 
Javascript Basic
Javascript BasicJavascript Basic
Javascript Basic
 
Ajax On S2 Odp
Ajax On S2 OdpAjax On S2 Odp
Ajax On S2 Odp
 

Plus de Yehuda Katz

Sprout core and performance
Sprout core and performanceSprout core and performance
Sprout core and performance
Yehuda Katz
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
Yehuda Katz
 
Organizing jQuery Projects Without OO
Organizing jQuery Projects Without OOOrganizing jQuery Projects Without OO
Organizing jQuery Projects Without OO
Yehuda Katz
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 

Plus de Yehuda Katz (10)

Sprout core and performance
Sprout core and performanceSprout core and performance
Sprout core and performance
 
Writing Fast Client-Side Code: Lessons Learned from SproutCore
Writing Fast Client-Side Code: Lessons Learned from SproutCoreWriting Fast Client-Side Code: Lessons Learned from SproutCore
Writing Fast Client-Side Code: Lessons Learned from SproutCore
 
SproutCore: Amber
SproutCore: AmberSproutCore: Amber
SproutCore: Amber
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Organizing jQuery Projects Without OO
Organizing jQuery Projects Without OOOrganizing jQuery Projects Without OO
Organizing jQuery Projects Without OO
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Merb Camp Keynote
Merb Camp KeynoteMerb Camp Keynote
Merb Camp Keynote
 
Merb
MerbMerb
Merb
 
DataMapper
DataMapperDataMapper
DataMapper
 
jQuery and Ruby Web Frameworks
jQuery and Ruby Web FrameworksjQuery and Ruby Web Frameworks
jQuery and Ruby Web Frameworks
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Merb jQuery