SlideShare uma empresa Scribd logo
1 de 17
Baixar para ler offline
Rails GUI Development
       with Ext JS
    martin.rehfeld@glnetworks.de
       @ RUG-B 10-Jan-2008
What‘s wrong with
ActionView::Helpers ?
• Nothing!
• But...
 • often feels like assembling a spacecraft
    molecule by molecule
  • which is fine for building the one GUI that
    no one else has, but get‘s boring for
    standard apps
Wouldn‘t it be nice, if...

• ... you had rich GUI components like
 • Data Grids
 • Tree Views
 • Tabs
 • Toolbars / Menus
Maybe Ext JS is for you




       http://www.extjs.com
Ext JS
• JavaScript Framework
• Dual-License: LGPL + Commercial
 • rich GUI components
 • interface to JSON or XML based
    data sources (~ web services)
 • keeps state in session, i.e. cookies
 •           cross-browser
    6+ 1.5+ 2+   9+
Segregation of Duties

•   Model: business as usual    •   program GUI and
                                    interactions in JavaScript
•   Controller: REST web
    service providing           •   use Rails backend to load
    special :ext_json format,       and persist data as needed
    handle page flow /
    redirects

•   View: provide layout,
    DOM structure and
    include JavaScript
Test Drive: Scaffolding
                          Data Grid with
                          toolbar and pagination




 Forms with validation
 (client side + server side)
Demo
Ext Scaffold Generator
• Create Rails app
  rails ext_demo


• Download & extract Ext to public/ext
  http://extjs.com/deploy/ext-2.0.zip


• Install ext_scaffold plugin:
  script/plugin install http://rug-b.rubyforge.org/svn/ext_scaffold


• Generate Demo resource
  script/generate ext_scaffold Post title:string body:text
  published:boolean visible_from:datetime visible_to:date ;
  rake db:migrate


• Enjoy :-)
  script/server -> http://localhost:3000/posts
Code
Model
• Nothing special :-)
  class Post < ActiveRecord::Base
    validates_presence_of :title, :message => quot;Title can't be blankquot;
  end



• Validation errors will be presented in forms
  just as Ext‘s own (client side) validation
  failures
• Ext Scaffold will return JSON error
  structure with per-field messages
Controller
• Support ext_json format -> render :json
  def index
    respond_to do |format|
      format.html     # index.html.erb (no data required)
      format.ext_json { render :json => Post.find(:all).to_ext_json }
    end
  end

  def create
    @post = Post.new(params[:post])

    respond_to do |format|
      if @post.save
        flash[:notice] = 'Post was successfully created.'
        format.ext_json { render(:update) {|page| page.redirect_to posts_url } }
      else
        format.ext_json { render :json => @post.to_ext_json(:success => false) }
      end
    end
  end

  ...
#to_ext_json ?
• Implemented as extension to Array and
  ActiveRecord::Base respectively
 • Array form
    {quot;resultsquot;: n,
      quot;postsquot;: [ {quot;idquot;: 1, quot;titlequot;: quot;First Postquot;,
                  quot;bodyquot;: quot;This is my first post.quot;, quot;publishedquot;: true, ... },
                  ...
               ]
    }




 • Single (valid) record
    {quot;dataquot;: { quot;post[id]quot;: 1, quot;post[title]quot;: quot;First Postquot;,
               quot;post[body]quot;: quot;This is my first post.quot;,
               quot;post[published]quot;: true, ...},
     quot;successquot;: true}
View
• Supported by (some tiny) helpers
  <% javascript_tag do -%>
    var post_form_items = [
       <%= ext_field(:field_label => 'Title', :name => 'post[title]',
                     :xtype => :text_field) %>,
       <%= ext_field(:field_label => 'Body', :name => 'post[body]',
                     :xtype => :text_area) %>,
       <%= ext_field(:field_label => 'Published', :name => 'post[published]',
                     :xtype => :check_box) %>,
       <%= ext_field(:field_label => 'Visible from', :name => 'post[visible_from]',
                     :xtype => :datetime_select) %>,
       <%= ext_field(:field_label => 'Visible to', :name => 'post[visible_to]',
                     :xtype => :date_select) %>
    ];
  <% end -%>

  <%= ext_form_for :post,
                   :element => 'post-form',
                   :form_items => :post_form_items,
                   :mode => :new %>
  <div id=quot;post-formquot;></div>
Resulting „HTML“
<script type=quot;text/javascriptquot;>
  var post_form_items = [
    { fieldLabel: 'Title',     xtype:   'textfield',                 name:   'post[title]'},
    { fieldLabel: 'Body',      xtype:   'textarea',                  name:   'post[body]'},
    { fieldLabel: 'Published', xtype:   'checkbox', inputValue: '1', name:   'post[published]'},
                             { xtype:   'hidden',        value: '0', name:   'post[published]' },
    ...
  ];

  Ext.onReady(function(){
    var panel = new Ext.FormPanel({
        url:        '/posts',
        title:      'Create Post',
        renderTo:   'post-form',
        baseParams: {authenticity_token: 'my_secret'},
        items:      post_form_items,
        buttons:    [ { text: 'Save', type: 'submit',
                          handler: function(){
                            panel.form.submit({url:    '/posts?format=ext_json',
                                               waitMsg:'Saving...'}); }},
                      { text: 'Back', handler: function(){ window.location.href = '/posts'; } }
                    ]
    });
  });
</script>
<div id=quot;post-formquot;></div>
Conclusion
• Using Ext gives
 • a very slim Rails backend,
    just as we like it            :-)
 • lots of JavaScript in the view :-(
 • then again:
    loads of functionality „for free“ and less
    involvement of the backend in user
    interactions                   :-))))
Q &A



!   Martin Rehfeld
    martin.rehfeld@glnetworks.de
    http://inside.glnetworks.de

Mais conteúdo relacionado

Mais procurados

Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0Eyal Vardi
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile ProcessEyal Vardi
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2Performance Optimization In Angular 2
Performance Optimization In Angular 2Eyal Vardi
 
Getting classy with ES6
Getting classy with ES6Getting classy with ES6
Getting classy with ES6Andy Sharman
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 ViewsEyal Vardi
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajaxbaygross
 
amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5mennovanslooten
 
Angular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.xAngular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.xEyal Vardi
 
Drupal sins 2016 10-06
Drupal sins 2016 10-06Drupal sins 2016 10-06
Drupal sins 2016 10-06Aaron Crosman
 
Game jump: frontend introduction #1
Game jump: frontend introduction #1Game jump: frontend introduction #1
Game jump: frontend introduction #1Sebastian Pożoga
 
Sins Against Drupal 2
Sins Against Drupal 2Sins Against Drupal 2
Sins Against Drupal 2Aaron Crosman
 
Modules and injector
Modules and injectorModules and injector
Modules and injectorEyal Vardi
 
Iterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory managementIterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory managementAdrian Cardenas
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And NavigationEyal Vardi
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS OverviewEyal Vardi
 

Mais procurados (20)

Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
 
22 j query1
22 j query122 j query1
22 j query1
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile Process
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2Performance Optimization In Angular 2
Performance Optimization In Angular 2
 
Getting classy with ES6
Getting classy with ES6Getting classy with ES6
Getting classy with ES6
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
 
amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5amsterdamjs - jQuery 1.5
amsterdamjs - jQuery 1.5
 
Angular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.xAngular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.x
 
Drupal sins 2016 10-06
Drupal sins 2016 10-06Drupal sins 2016 10-06
Drupal sins 2016 10-06
 
Game jump: frontend introduction #1
Game jump: frontend introduction #1Game jump: frontend introduction #1
Game jump: frontend introduction #1
 
Sins Against Drupal 2
Sins Against Drupal 2Sins Against Drupal 2
Sins Against Drupal 2
 
Modules and injector
Modules and injectorModules and injector
Modules and injector
 
Iterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory managementIterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory management
 
Routing And Navigation
Routing And NavigationRouting And Navigation
Routing And Navigation
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
 
Symfony2. Form and Validation
Symfony2. Form and ValidationSymfony2. Form and Validation
Symfony2. Form and Validation
 
J Query Public
J Query PublicJ Query Public
J Query Public
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
 
5. hello popescu
5. hello popescu5. hello popescu
5. hello popescu
 

Destaque

Gui Development with qooxdoo
Gui Development with qooxdooGui Development with qooxdoo
Gui Development with qooxdooSebastian Werner
 
Gui application development guidelines
Gui application development guidelinesGui application development guidelines
Gui application development guidelinesLOUIS WAYNE
 
Graphical User Interface
Graphical User Interface Graphical User Interface
Graphical User Interface Bivek Pakuwal
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)Bilal Amjad
 

Destaque (7)

01 gui 01
01 gui 0101 gui 01
01 gui 01
 
Gui Development with qooxdoo
Gui Development with qooxdooGui Development with qooxdoo
Gui Development with qooxdoo
 
02 gui 02
02 gui 0202 gui 02
02 gui 02
 
Gui application development guidelines
Gui application development guidelinesGui application development guidelines
Gui application development guidelines
 
Graphical User Interface
Graphical User Interface Graphical User Interface
Graphical User Interface
 
Graphical User Interface (Gui)
Graphical User Interface (Gui)Graphical User Interface (Gui)
Graphical User Interface (Gui)
 
Macintosh vs. windows
Macintosh vs. windowsMacintosh vs. windows
Macintosh vs. windows
 

Semelhante a Rails GUI Development with Ext JS

Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous MerbMatt Todd
 
Implementation of GUI Framework part3
Implementation of GUI Framework part3Implementation of GUI Framework part3
Implementation of GUI Framework part3masahiroookubo
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsMike Subelsky
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsMike Subelsky
 
Acceptance Testing with Webrat
Acceptance Testing with WebratAcceptance Testing with Webrat
Acceptance Testing with WebratLuismi Cavallé
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Foreverstephskardal
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
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 prazosIgor Sobreira
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialYi-Ting Cheng
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)Igor Bronovskyy
 
GHC Participant Training
GHC Participant TrainingGHC Participant Training
GHC Participant TrainingAidIQ
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of usOSCON Byrum
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
Aprimorando sua Aplicação com Ext JS 4 - BrazilJS
Aprimorando sua Aplicação com Ext JS 4 - BrazilJSAprimorando sua Aplicação com Ext JS 4 - BrazilJS
Aprimorando sua Aplicação com Ext JS 4 - BrazilJSLoiane Groner
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoRob Bontekoe
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkDirk Haun
 

Semelhante a Rails GUI Development with Ext JS (20)

Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous Merb
 
Implementation of GUI Framework part3
Implementation of GUI Framework part3Implementation of GUI Framework part3
Implementation of GUI Framework part3
 
Java script
Java scriptJava script
Java script
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Rails <form> Chronicle
Rails <form> ChronicleRails <form> Chronicle
Rails <form> Chronicle
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Acceptance Testing with Webrat
Acceptance Testing with WebratAcceptance Testing with Webrat
Acceptance Testing with Webrat
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Forever
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
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
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
 
Jsf Ajax
Jsf AjaxJsf Ajax
Jsf Ajax
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
GHC Participant Training
GHC Participant TrainingGHC Participant Training
GHC Participant Training
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of us
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Aprimorando sua Aplicação com Ext JS 4 - BrazilJS
Aprimorando sua Aplicação com Ext JS 4 - BrazilJSAprimorando sua Aplicação com Ext JS 4 - BrazilJS
Aprimorando sua Aplicação com Ext JS 4 - BrazilJS
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 

Último

Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Anamaria Contreras
 
Effective Strategies for Maximizing Your Profit When Selling Gold Jewelry
Effective Strategies for Maximizing Your Profit When Selling Gold JewelryEffective Strategies for Maximizing Your Profit When Selling Gold Jewelry
Effective Strategies for Maximizing Your Profit When Selling Gold JewelryWhittensFineJewelry1
 
Darshan Hiranandani [News About Next CEO].pdf
Darshan Hiranandani [News About Next CEO].pdfDarshan Hiranandani [News About Next CEO].pdf
Darshan Hiranandani [News About Next CEO].pdfShashank Mehta
 
APRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfAPRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfRbc Rbcua
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03DallasHaselhorst
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMVoces Mineras
 
20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdf20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdfChris Skinner
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationAnamaria Contreras
 
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptxThe-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptxmbikashkanyari
 
Supercharge Your eCommerce Stores-acowebs
Supercharge Your eCommerce Stores-acowebsSupercharge Your eCommerce Stores-acowebs
Supercharge Your eCommerce Stores-acowebsGOKUL JS
 
Send Files | Sendbig.comSend Files | Sendbig.com
Send Files | Sendbig.comSend Files | Sendbig.comSend Files | Sendbig.comSend Files | Sendbig.com
Send Files | Sendbig.comSend Files | Sendbig.comSendBig4
 
Welding Electrode Making Machine By Deccan Dynamics
Welding Electrode Making Machine By Deccan DynamicsWelding Electrode Making Machine By Deccan Dynamics
Welding Electrode Making Machine By Deccan DynamicsIndiaMART InterMESH Limited
 
Horngren’s Financial & Managerial Accounting, 7th edition by Miller-Nobles so...
Horngren’s Financial & Managerial Accounting, 7th edition by Miller-Nobles so...Horngren’s Financial & Managerial Accounting, 7th edition by Miller-Nobles so...
Horngren’s Financial & Managerial Accounting, 7th edition by Miller-Nobles so...ssuserf63bd7
 
Jewish Resources in the Family Resource Centre
Jewish Resources in the Family Resource CentreJewish Resources in the Family Resource Centre
Jewish Resources in the Family Resource CentreNZSG
 
Pitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deckPitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deckHajeJanKamps
 
Cyber Security Training in Office Environment
Cyber Security Training in Office EnvironmentCyber Security Training in Office Environment
Cyber Security Training in Office Environmentelijahj01012
 
Technical Leaders - Working with the Management Team
Technical Leaders - Working with the Management TeamTechnical Leaders - Working with the Management Team
Technical Leaders - Working with the Management TeamArik Fletcher
 
Lucia Ferretti, Lead Business Designer; Matteo Meschini, Business Designer @T...
Lucia Ferretti, Lead Business Designer; Matteo Meschini, Business Designer @T...Lucia Ferretti, Lead Business Designer; Matteo Meschini, Business Designer @T...
Lucia Ferretti, Lead Business Designer; Matteo Meschini, Business Designer @T...Associazione Digital Days
 

Último (20)

Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.
 
The Bizz Quiz-E-Summit-E-Cell-IITPatna.pptx
The Bizz Quiz-E-Summit-E-Cell-IITPatna.pptxThe Bizz Quiz-E-Summit-E-Cell-IITPatna.pptx
The Bizz Quiz-E-Summit-E-Cell-IITPatna.pptx
 
Effective Strategies for Maximizing Your Profit When Selling Gold Jewelry
Effective Strategies for Maximizing Your Profit When Selling Gold JewelryEffective Strategies for Maximizing Your Profit When Selling Gold Jewelry
Effective Strategies for Maximizing Your Profit When Selling Gold Jewelry
 
Darshan Hiranandani [News About Next CEO].pdf
Darshan Hiranandani [News About Next CEO].pdfDarshan Hiranandani [News About Next CEO].pdf
Darshan Hiranandani [News About Next CEO].pdf
 
APRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfAPRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdf
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQM
 
20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdf20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdf
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement Presentation
 
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptxThe-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
 
Supercharge Your eCommerce Stores-acowebs
Supercharge Your eCommerce Stores-acowebsSupercharge Your eCommerce Stores-acowebs
Supercharge Your eCommerce Stores-acowebs
 
WAM Corporate Presentation April 12 2024.pdf
WAM Corporate Presentation April 12 2024.pdfWAM Corporate Presentation April 12 2024.pdf
WAM Corporate Presentation April 12 2024.pdf
 
Send Files | Sendbig.comSend Files | Sendbig.com
Send Files | Sendbig.comSend Files | Sendbig.comSend Files | Sendbig.comSend Files | Sendbig.com
Send Files | Sendbig.comSend Files | Sendbig.com
 
Welding Electrode Making Machine By Deccan Dynamics
Welding Electrode Making Machine By Deccan DynamicsWelding Electrode Making Machine By Deccan Dynamics
Welding Electrode Making Machine By Deccan Dynamics
 
Horngren’s Financial & Managerial Accounting, 7th edition by Miller-Nobles so...
Horngren’s Financial & Managerial Accounting, 7th edition by Miller-Nobles so...Horngren’s Financial & Managerial Accounting, 7th edition by Miller-Nobles so...
Horngren’s Financial & Managerial Accounting, 7th edition by Miller-Nobles so...
 
Jewish Resources in the Family Resource Centre
Jewish Resources in the Family Resource CentreJewish Resources in the Family Resource Centre
Jewish Resources in the Family Resource Centre
 
Pitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deckPitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deck
 
Cyber Security Training in Office Environment
Cyber Security Training in Office EnvironmentCyber Security Training in Office Environment
Cyber Security Training in Office Environment
 
Technical Leaders - Working with the Management Team
Technical Leaders - Working with the Management TeamTechnical Leaders - Working with the Management Team
Technical Leaders - Working with the Management Team
 
Lucia Ferretti, Lead Business Designer; Matteo Meschini, Business Designer @T...
Lucia Ferretti, Lead Business Designer; Matteo Meschini, Business Designer @T...Lucia Ferretti, Lead Business Designer; Matteo Meschini, Business Designer @T...
Lucia Ferretti, Lead Business Designer; Matteo Meschini, Business Designer @T...
 

Rails GUI Development with Ext JS

  • 1. Rails GUI Development with Ext JS martin.rehfeld@glnetworks.de @ RUG-B 10-Jan-2008
  • 2. What‘s wrong with ActionView::Helpers ? • Nothing! • But... • often feels like assembling a spacecraft molecule by molecule • which is fine for building the one GUI that no one else has, but get‘s boring for standard apps
  • 3. Wouldn‘t it be nice, if... • ... you had rich GUI components like • Data Grids • Tree Views • Tabs • Toolbars / Menus
  • 4. Maybe Ext JS is for you http://www.extjs.com
  • 5. Ext JS • JavaScript Framework • Dual-License: LGPL + Commercial • rich GUI components • interface to JSON or XML based data sources (~ web services) • keeps state in session, i.e. cookies • cross-browser 6+ 1.5+ 2+ 9+
  • 6. Segregation of Duties • Model: business as usual • program GUI and interactions in JavaScript • Controller: REST web service providing • use Rails backend to load special :ext_json format, and persist data as needed handle page flow / redirects • View: provide layout, DOM structure and include JavaScript
  • 7. Test Drive: Scaffolding Data Grid with toolbar and pagination Forms with validation (client side + server side)
  • 9. Ext Scaffold Generator • Create Rails app rails ext_demo • Download & extract Ext to public/ext http://extjs.com/deploy/ext-2.0.zip • Install ext_scaffold plugin: script/plugin install http://rug-b.rubyforge.org/svn/ext_scaffold • Generate Demo resource script/generate ext_scaffold Post title:string body:text published:boolean visible_from:datetime visible_to:date ; rake db:migrate • Enjoy :-) script/server -> http://localhost:3000/posts
  • 10. Code
  • 11. Model • Nothing special :-) class Post < ActiveRecord::Base validates_presence_of :title, :message => quot;Title can't be blankquot; end • Validation errors will be presented in forms just as Ext‘s own (client side) validation failures • Ext Scaffold will return JSON error structure with per-field messages
  • 12. Controller • Support ext_json format -> render :json def index respond_to do |format| format.html # index.html.erb (no data required) format.ext_json { render :json => Post.find(:all).to_ext_json } end end def create @post = Post.new(params[:post]) respond_to do |format| if @post.save flash[:notice] = 'Post was successfully created.' format.ext_json { render(:update) {|page| page.redirect_to posts_url } } else format.ext_json { render :json => @post.to_ext_json(:success => false) } end end end ...
  • 13. #to_ext_json ? • Implemented as extension to Array and ActiveRecord::Base respectively • Array form {quot;resultsquot;: n, quot;postsquot;: [ {quot;idquot;: 1, quot;titlequot;: quot;First Postquot;, quot;bodyquot;: quot;This is my first post.quot;, quot;publishedquot;: true, ... }, ... ] } • Single (valid) record {quot;dataquot;: { quot;post[id]quot;: 1, quot;post[title]quot;: quot;First Postquot;, quot;post[body]quot;: quot;This is my first post.quot;, quot;post[published]quot;: true, ...}, quot;successquot;: true}
  • 14. View • Supported by (some tiny) helpers <% javascript_tag do -%> var post_form_items = [ <%= ext_field(:field_label => 'Title', :name => 'post[title]', :xtype => :text_field) %>, <%= ext_field(:field_label => 'Body', :name => 'post[body]', :xtype => :text_area) %>, <%= ext_field(:field_label => 'Published', :name => 'post[published]', :xtype => :check_box) %>, <%= ext_field(:field_label => 'Visible from', :name => 'post[visible_from]', :xtype => :datetime_select) %>, <%= ext_field(:field_label => 'Visible to', :name => 'post[visible_to]', :xtype => :date_select) %> ]; <% end -%> <%= ext_form_for :post, :element => 'post-form', :form_items => :post_form_items, :mode => :new %> <div id=quot;post-formquot;></div>
  • 15. Resulting „HTML“ <script type=quot;text/javascriptquot;> var post_form_items = [ { fieldLabel: 'Title', xtype: 'textfield', name: 'post[title]'}, { fieldLabel: 'Body', xtype: 'textarea', name: 'post[body]'}, { fieldLabel: 'Published', xtype: 'checkbox', inputValue: '1', name: 'post[published]'}, { xtype: 'hidden', value: '0', name: 'post[published]' }, ... ]; Ext.onReady(function(){ var panel = new Ext.FormPanel({ url: '/posts', title: 'Create Post', renderTo: 'post-form', baseParams: {authenticity_token: 'my_secret'}, items: post_form_items, buttons: [ { text: 'Save', type: 'submit', handler: function(){ panel.form.submit({url: '/posts?format=ext_json', waitMsg:'Saving...'}); }}, { text: 'Back', handler: function(){ window.location.href = '/posts'; } } ] }); }); </script> <div id=quot;post-formquot;></div>
  • 16. Conclusion • Using Ext gives • a very slim Rails backend, just as we like it :-) • lots of JavaScript in the view :-( • then again: loads of functionality „for free“ and less involvement of the backend in user interactions :-))))
  • 17. Q &A ! Martin Rehfeld martin.rehfeld@glnetworks.de http://inside.glnetworks.de