SlideShare a Scribd company logo
Creación de Aplicaciones Móviles con Ruby on Rails Jürgen Feßlmeier @chinshr fesslmeier @codecuisine.de
Lo que el cliente quería +  ?  =
¿Lo que acabamos usando? jqTouch JavaScript biblioteca basado en jQuery HTML5/CSS3 Controls emulados WebKit Browsers Mobile Safari, Chrome Android Open Source PhoneGap Sirve como container de la aplicación Web Framework para crear aplicaciones nativas con tecnologías Web iPhone, Android, Palm, Symbian, Blackberry
Así empezamos config/initializers/mime_types.rb ... Mime::Type.register_alias  "text/html" ,  :jqtouch ...
Detectar user agent app/controllers/application_controller.rb class  ApplicationController < ActionController::Base before_filter  :adjust_request_format_for_mobile_device layout  &quot;application&quot; def  index format.jqtouch {}  end protected def  adjust_request_format_for_mobile_device request.format = :jqtouch \ if request.user_agent =~  /iphone|ipod|ipad/i end end
Layout app/views/layout/application.jqtouch.erb <!doctype html> <html> <head> <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /> <meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0&quot; /> <meta name=&quot;apple-mobile-web-app-capable&quot; content=&quot;yes&quot; /> <title>jQTouch App</title> <script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;> var jQT = new $.jQTouch({ icon: 'appicon.png', addGlossToIcon: true, startupScreen: 'appsplash.png', statusBar: 'default', ... }); </script> <style type=&quot;text/css&quot; media=&quot;screen&quot;> /* Custom Style */ </style> </head> <body> <div id=&quot;jqt&quot;> <%=  yield  %> </div> </body> </html>
Pagina principal app/views/application_controller/index.jqtouch.erb <!-- home --> <div id=&quot; home &quot; class=&quot; current &quot; style=&quot;top: 0px; &quot;> <div class=&quot;toolbar&quot;><a class=&quot;button logout&quot; href=&quot;http://127.0.0.1:3000/m/session/destroy&quot;>Logout</a> <div class=&quot;logo&quot;></div> </div> <div class=&quot;vertical-scroll&quot;><div style=&quot;-webkit-transform: translate3d(0px, 0px, 0px); -webkit-transition-duration: 0ms; -webkit-transition-timing-function: cubic-bezier(0, 0, 0.2, 1); &quot;> <div class=&quot;startscreen&quot;> <div class=&quot;image&quot;> <h1>Banking mit &nbsp;Freunden!</h1> <i class=&quot;bubble1&quot;>„Endlich ehrliche Geldtipps und <br>Ratschläge von anderen Usern“</i>  <i class=&quot;bubble2&quot;>„Die erste Bank die mir für meine<br>online Aktivitäten Geld gibt“</i>  </div> </div> <ul class=&quot;main&quot;> <li class=&quot;quest&quot;> <a href=&quot;http://127.0.0.1:3000/m/community&quot; class=&quot;required&quot;>Community</a> </li> <li class=&quot;euro_arrow&quot;> <a href=&quot;http://127.0.0.1:3000/m/banking/transactions&quot; class=&quot;required&quot;>Transaktionen</a> </li> <li class=&quot;euro&quot;> <a href=&quot;http://127.0.0.1:3000/m/banking/my_money&quot; class=&quot;required&quot;>Mein Geld</a> </li> </ul>  <ul class=&quot;reco&quot;> <li><a href=&quot;&quot;>Information</a></li> </ul> <p class=&quot;info&quot;> Gemeinsam mehr Geld. </p> </div></div> </div> <form  id=” question ” action=&quot;/question/create&quot;> <div class=&quot;toolbar&quot;> <h1>Geldfrage</h1> <a class=&quot;back&quot;>Back</a> <a class=&quot;button&quot; href=&quot;/session/destroy&quot;>Logout</a> </div> <ul class=&quot;rounded&quot;> <li><textarea placeholder=&quot;Question&quot; name=&quot;smart_question[question]&quot;></textarea></li> <li>Anonym<span class=&quot;toggle&quot;><input type=&quot;checkbox&quot; name=&quot;smart_question[anonymous]&quot;/></span></li> </ul> <a class=&quot;whiteButton submit&quot;>Send</a>  </form> <div id=&quot; foo &quot;> ... </div>
Controller Simple app/controllers/questions_controller.rb class  QuestionsController < ApplicationController def  new format.jqtouch {} end def  create ... end  end
Formulario simple app/views/questions/new.jqtouch.erb <form  id=”question” action=&quot;/question/create&quot;> <div class=&quot;toolbar&quot;> <h1>Geldfrage</h1> <a class=&quot;back&quot;>Back</a> <a class=&quot;button&quot; href=&quot;/session/destroy&quot;>Logout</a> </div> <ul class=&quot;rounded&quot;> <li><textarea placeholder=&quot;Question&quot; name=&quot;smart_question[question]&quot;></textarea></li> <li>Anonym<span class=&quot;toggle&quot;><input type=&quot;checkbox&quot; name=&quot;smart_question[anonymous]&quot;/></span></li> </ul> <a class=&quot;whiteButton submit&quot;>Send</a>  </form>
¿Como hacer  render ? app/controllers/questions_controller.rb class  QuestionsController < ApplicationController def   new format.jqtouch {} end def   create @question = Question.new params[:question] if @question.save render :action => &quot;show&quot;, :layout =>  false else render :action => &quot;new&quot;, :layout =>  false end  end  end
¿Como hacer  redirect ? app/controllers/questions_controller.rb class  QuestionsController < ApplicationController def create ... #  redirect_to  no funciona...entonces render_json_response :redirect, :to => &quot;/sessions/new&quot; ... end protected def render_json_response(type, options={})  ... end end
No hay, entonces  redirect  con JSON app/controllers/questions_controller.rb class  QuestionsController < ApplicationController def  create ... end protected def  render_json_response(type, options={})  default_json_structure = {:status => type,  :html => nil, :js => nil, :message => nil,  :to => nil, :user_id => nil}.merge(options) render_options = {:json => default_json_structure} render_options[:status] = 400 if type == :error render(render_options) end end
El cliente recibe JSON {status:&quot;redirect&quot;,to:&quot;/sessions/new#login&quot;} {status:&quot;error&quot;,message:&quot;Try again!&quot;} {status:&quot;ok&quot;,js:&quot;alert('Success!');&quot;} {status:&quot;error&quot;,html:&quot;<div id=&quot;foo&quot;>...&quot;}
El cliente recibe JSON public/jqtouch/mobile.js var app = { json: function ($form) { $.ajax({ type:$form.attr(&quot;method&quot;), url:$form.attr(&quot;action&quot;), dataType:&quot;json&quot;, data:$form.serialize(), complete:function (XMLHttpRequest, textStatus) { var jsonResponse = window.eval(&quot;(&quot; + XMLHttpRequest.responseText + &quot;)&quot;); if (jsonResponse.status ==  &quot;error&quot; ) { alert(jsonResponse.message); } elsif (jsonResponse.status ==  &quot;redirect&quot; ) { // insert page } } });  return false; }, ... } var jsonFn =  function (e) { var $form = $(this).closest(&quot;form&quot;); return app.json($form); }; $(&quot;form.json a.send&quot;).live(&quot;tap&quot;, jsonFn); $(&quot;form.json&quot;).live(&quot;submit&quot;, jsonFn);
PhoneGap Download  http://www.phonegap.com/ XCode  http://developer.apple.com/ Build PhoneGap plugin y agregar a Xcode Archivos estaticos van a
Xcode IDE
Demo

More Related Content

PDF
Mavaigajan Visual basic 06
PPTX
Lecture III Muscle Imbalances
PDF
mavaigajan notes ( mail merge -word 2003)
PPTX
Elm: Make Yourself A Happy Front-end Web Developer
PPTX
Geekcamp ID 2015: Programmable Music
PPT
Git Heaven with Wakanda
DOC
Solved 2
PDF
Tanibox: ID IoT Dev Day Jakarta 2016
Mavaigajan Visual basic 06
Lecture III Muscle Imbalances
mavaigajan notes ( mail merge -word 2003)
Elm: Make Yourself A Happy Front-end Web Developer
Geekcamp ID 2015: Programmable Music
Git Heaven with Wakanda
Solved 2
Tanibox: ID IoT Dev Day Jakarta 2016

Similar to Rails iPhone App (11)

PPTX
Aspetos gerais de desenvolvimento web.
PPSX
初识 Html5
PDF
Komplexe Sites sauber aufbauen
PPT
BDD no mundo real
PPT
Html Frameset
PPTX
TYPO3 TypoScript: IF, CASE, CONDITIONS
PPT
Chico-UI en escuela DaVinci
PPT
Tech conf2009 eiji_shinohara
ODP
Der lachende Dritte
PPTX
Soa for DEVs
PPTX
ADO.NET Entity Framework 4
Aspetos gerais de desenvolvimento web.
初识 Html5
Komplexe Sites sauber aufbauen
BDD no mundo real
Html Frameset
TYPO3 TypoScript: IF, CASE, CONDITIONS
Chico-UI en escuela DaVinci
Tech conf2009 eiji_shinohara
Der lachende Dritte
Soa for DEVs
ADO.NET Entity Framework 4
Ad

Rails iPhone App

  • 1. Creación de Aplicaciones Móviles con Ruby on Rails Jürgen Feßlmeier @chinshr fesslmeier @codecuisine.de
  • 2. Lo que el cliente quería + ? =
  • 3. ¿Lo que acabamos usando? jqTouch JavaScript biblioteca basado en jQuery HTML5/CSS3 Controls emulados WebKit Browsers Mobile Safari, Chrome Android Open Source PhoneGap Sirve como container de la aplicación Web Framework para crear aplicaciones nativas con tecnologías Web iPhone, Android, Palm, Symbian, Blackberry
  • 4. Así empezamos config/initializers/mime_types.rb ... Mime::Type.register_alias &quot;text/html&quot; , :jqtouch ...
  • 5. Detectar user agent app/controllers/application_controller.rb class ApplicationController < ActionController::Base before_filter :adjust_request_format_for_mobile_device layout &quot;application&quot; def index format.jqtouch {} end protected def adjust_request_format_for_mobile_device request.format = :jqtouch \ if request.user_agent =~ /iphone|ipod|ipad/i end end
  • 6. Layout app/views/layout/application.jqtouch.erb <!doctype html> <html> <head> <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /> <meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0&quot; /> <meta name=&quot;apple-mobile-web-app-capable&quot; content=&quot;yes&quot; /> <title>jQTouch App</title> <script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;> var jQT = new $.jQTouch({ icon: 'appicon.png', addGlossToIcon: true, startupScreen: 'appsplash.png', statusBar: 'default', ... }); </script> <style type=&quot;text/css&quot; media=&quot;screen&quot;> /* Custom Style */ </style> </head> <body> <div id=&quot;jqt&quot;> <%= yield %> </div> </body> </html>
  • 7. Pagina principal app/views/application_controller/index.jqtouch.erb <!-- home --> <div id=&quot; home &quot; class=&quot; current &quot; style=&quot;top: 0px; &quot;> <div class=&quot;toolbar&quot;><a class=&quot;button logout&quot; href=&quot;http://127.0.0.1:3000/m/session/destroy&quot;>Logout</a> <div class=&quot;logo&quot;></div> </div> <div class=&quot;vertical-scroll&quot;><div style=&quot;-webkit-transform: translate3d(0px, 0px, 0px); -webkit-transition-duration: 0ms; -webkit-transition-timing-function: cubic-bezier(0, 0, 0.2, 1); &quot;> <div class=&quot;startscreen&quot;> <div class=&quot;image&quot;> <h1>Banking mit &nbsp;Freunden!</h1> <i class=&quot;bubble1&quot;>„Endlich ehrliche Geldtipps und <br>Ratschläge von anderen Usern“</i> <i class=&quot;bubble2&quot;>„Die erste Bank die mir für meine<br>online Aktivitäten Geld gibt“</i> </div> </div> <ul class=&quot;main&quot;> <li class=&quot;quest&quot;> <a href=&quot;http://127.0.0.1:3000/m/community&quot; class=&quot;required&quot;>Community</a> </li> <li class=&quot;euro_arrow&quot;> <a href=&quot;http://127.0.0.1:3000/m/banking/transactions&quot; class=&quot;required&quot;>Transaktionen</a> </li> <li class=&quot;euro&quot;> <a href=&quot;http://127.0.0.1:3000/m/banking/my_money&quot; class=&quot;required&quot;>Mein Geld</a> </li> </ul> <ul class=&quot;reco&quot;> <li><a href=&quot;&quot;>Information</a></li> </ul> <p class=&quot;info&quot;> Gemeinsam mehr Geld. </p> </div></div> </div> <form id=” question ” action=&quot;/question/create&quot;> <div class=&quot;toolbar&quot;> <h1>Geldfrage</h1> <a class=&quot;back&quot;>Back</a> <a class=&quot;button&quot; href=&quot;/session/destroy&quot;>Logout</a> </div> <ul class=&quot;rounded&quot;> <li><textarea placeholder=&quot;Question&quot; name=&quot;smart_question[question]&quot;></textarea></li> <li>Anonym<span class=&quot;toggle&quot;><input type=&quot;checkbox&quot; name=&quot;smart_question[anonymous]&quot;/></span></li> </ul> <a class=&quot;whiteButton submit&quot;>Send</a> </form> <div id=&quot; foo &quot;> ... </div>
  • 8. Controller Simple app/controllers/questions_controller.rb class QuestionsController < ApplicationController def new format.jqtouch {} end def create ... end end
  • 9. Formulario simple app/views/questions/new.jqtouch.erb <form id=”question” action=&quot;/question/create&quot;> <div class=&quot;toolbar&quot;> <h1>Geldfrage</h1> <a class=&quot;back&quot;>Back</a> <a class=&quot;button&quot; href=&quot;/session/destroy&quot;>Logout</a> </div> <ul class=&quot;rounded&quot;> <li><textarea placeholder=&quot;Question&quot; name=&quot;smart_question[question]&quot;></textarea></li> <li>Anonym<span class=&quot;toggle&quot;><input type=&quot;checkbox&quot; name=&quot;smart_question[anonymous]&quot;/></span></li> </ul> <a class=&quot;whiteButton submit&quot;>Send</a> </form>
  • 10. ¿Como hacer render ? app/controllers/questions_controller.rb class QuestionsController < ApplicationController def new format.jqtouch {} end def create @question = Question.new params[:question] if @question.save render :action => &quot;show&quot;, :layout => false else render :action => &quot;new&quot;, :layout => false end end end
  • 11. ¿Como hacer redirect ? app/controllers/questions_controller.rb class QuestionsController < ApplicationController def create ... # redirect_to no funciona...entonces render_json_response :redirect, :to => &quot;/sessions/new&quot; ... end protected def render_json_response(type, options={}) ... end end
  • 12. No hay, entonces redirect con JSON app/controllers/questions_controller.rb class QuestionsController < ApplicationController def create ... end protected def render_json_response(type, options={}) default_json_structure = {:status => type, :html => nil, :js => nil, :message => nil, :to => nil, :user_id => nil}.merge(options) render_options = {:json => default_json_structure} render_options[:status] = 400 if type == :error render(render_options) end end
  • 13. El cliente recibe JSON {status:&quot;redirect&quot;,to:&quot;/sessions/new#login&quot;} {status:&quot;error&quot;,message:&quot;Try again!&quot;} {status:&quot;ok&quot;,js:&quot;alert('Success!');&quot;} {status:&quot;error&quot;,html:&quot;<div id=&quot;foo&quot;>...&quot;}
  • 14. El cliente recibe JSON public/jqtouch/mobile.js var app = { json: function ($form) { $.ajax({ type:$form.attr(&quot;method&quot;), url:$form.attr(&quot;action&quot;), dataType:&quot;json&quot;, data:$form.serialize(), complete:function (XMLHttpRequest, textStatus) { var jsonResponse = window.eval(&quot;(&quot; + XMLHttpRequest.responseText + &quot;)&quot;); if (jsonResponse.status == &quot;error&quot; ) { alert(jsonResponse.message); } elsif (jsonResponse.status == &quot;redirect&quot; ) { // insert page } } }); return false; }, ... } var jsonFn = function (e) { var $form = $(this).closest(&quot;form&quot;); return app.json($form); }; $(&quot;form.json a.send&quot;).live(&quot;tap&quot;, jsonFn); $(&quot;form.json&quot;).live(&quot;submit&quot;, jsonFn);
  • 15. PhoneGap Download http://www.phonegap.com/ XCode http://developer.apple.com/ Build PhoneGap plugin y agregar a Xcode Archivos estaticos van a
  • 17. Demo