SlideShare una empresa de Scribd logo
1 de 17
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? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
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 ,[object Object],[object Object],[object Object],[object Object]
Xcode IDE
Demo

Más contenido relacionado

Similar a Rails iPhone App

Aspetos gerais de desenvolvimento web.
Aspetos gerais de desenvolvimento web.Aspetos gerais de desenvolvimento web.
Aspetos gerais de desenvolvimento web.Corcioli
 
Komplexe Sites sauber aufbauen
Komplexe Sites sauber aufbauenKomplexe Sites sauber aufbauen
Komplexe Sites sauber aufbauenJens Grochtdreis
 
TYPO3 TypoScript: IF, CASE, CONDITIONS
TYPO3 TypoScript: IF, CASE, CONDITIONSTYPO3 TypoScript: IF, CASE, CONDITIONS
TYPO3 TypoScript: IF, CASE, CONDITIONSAlex Kellner
 
Chico-UI en escuela DaVinci
Chico-UI en escuela DaVinciChico-UI en escuela DaVinci
Chico-UI en escuela DaVinciNatan Santolo
 
Tech conf2009 eiji_shinohara
Tech conf2009 eiji_shinoharaTech conf2009 eiji_shinohara
Tech conf2009 eiji_shinoharaEiji Shinohara
 
ADO.NET Entity Framework 4
ADO.NET Entity Framework 4ADO.NET Entity Framework 4
ADO.NET Entity Framework 4Raffaele Fanizzi
 

Similar a Rails iPhone App (11)

Aspetos gerais de desenvolvimento web.
Aspetos gerais de desenvolvimento web.Aspetos gerais de desenvolvimento web.
Aspetos gerais de desenvolvimento web.
 
初识 Html5
初识 Html5初识 Html5
初识 Html5
 
Komplexe Sites sauber aufbauen
Komplexe Sites sauber aufbauenKomplexe Sites sauber aufbauen
Komplexe Sites sauber aufbauen
 
BDD no mundo real
BDD no mundo realBDD no mundo real
BDD no mundo real
 
Html Frameset
Html FramesetHtml Frameset
Html Frameset
 
TYPO3 TypoScript: IF, CASE, CONDITIONS
TYPO3 TypoScript: IF, CASE, CONDITIONSTYPO3 TypoScript: IF, CASE, CONDITIONS
TYPO3 TypoScript: IF, CASE, CONDITIONS
 
Chico-UI en escuela DaVinci
Chico-UI en escuela DaVinciChico-UI en escuela DaVinci
Chico-UI en escuela DaVinci
 
Tech conf2009 eiji_shinohara
Tech conf2009 eiji_shinoharaTech conf2009 eiji_shinohara
Tech conf2009 eiji_shinohara
 
Der lachende Dritte
Der lachende DritteDer lachende Dritte
Der lachende Dritte
 
Soa for DEVs
Soa for DEVsSoa for DEVs
Soa for DEVs
 
ADO.NET Entity Framework 4
ADO.NET Entity Framework 4ADO.NET Entity Framework 4
ADO.NET Entity Framework 4
 

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.
  • 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.
  • 17. Demo