SlideShare a Scribd company logo
1 of 17
Download to read 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

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked

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
 

Viewers also liked (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
 

Similar to 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
 

Similar to 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
 

Recently uploaded

High Profile Bangalore Just VIP Brigade Road 100% Genuine at your Door Step
High Profile Bangalore Just VIP Brigade Road 100% Genuine at your Door StepHigh Profile Bangalore Just VIP Brigade Road 100% Genuine at your Door Step
High Profile Bangalore Just VIP Brigade Road 100% Genuine at your Door Stepdarmandersingh4580
 
stock price prediction using machine learning
stock price prediction using machine learningstock price prediction using machine learning
stock price prediction using machine learninggauravwankar27
 
Creating an Income Statement with Forecasts: A Simple Guide and Free Excel Te...
Creating an Income Statement with Forecasts: A Simple Guide and Free Excel Te...Creating an Income Statement with Forecasts: A Simple Guide and Free Excel Te...
Creating an Income Statement with Forecasts: A Simple Guide and Free Excel Te...Aurelien Domont, MBA
 
How to refresh to be fit for the future world
How to refresh to be fit for the future worldHow to refresh to be fit for the future world
How to refresh to be fit for the future worldChris Skinner
 
A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...
A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...
A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...prakheeshc
 
如何办理(SUT毕业证书)斯威本科技大学毕业证成绩单本科硕士学位证留信学历认证
如何办理(SUT毕业证书)斯威本科技大学毕业证成绩单本科硕士学位证留信学历认证如何办理(SUT毕业证书)斯威本科技大学毕业证成绩单本科硕士学位证留信学历认证
如何办理(SUT毕业证书)斯威本科技大学毕业证成绩单本科硕士学位证留信学历认证ogawka
 
First Time Home Buyer's Guide - KM Realty Group LLC
First Time Home Buyer's Guide - KM Realty Group LLCFirst Time Home Buyer's Guide - KM Realty Group LLC
First Time Home Buyer's Guide - KM Realty Group LLCTammy Jackson
 
The Art of Decision-Making: Navigating Complexity and Uncertainty
The Art of Decision-Making: Navigating Complexity and UncertaintyThe Art of Decision-Making: Navigating Complexity and Uncertainty
The Art of Decision-Making: Navigating Complexity and Uncertaintycapivisgroup
 
South Africa's 10 Most Influential CIOs to Watch.pdf
South Africa's 10 Most Influential CIOs to Watch.pdfSouth Africa's 10 Most Influential CIOs to Watch.pdf
South Africa's 10 Most Influential CIOs to Watch.pdfTHECIOWORLD
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfmstarkes24
 
tekAura | Desktop Procedure Template (2016)
tekAura | Desktop Procedure Template (2016)tekAura | Desktop Procedure Template (2016)
tekAura | Desktop Procedure Template (2016)Norah Medlin
 
wagamamaLab presentation @MIT 20240509 IRODORI
wagamamaLab presentation @MIT 20240509 IRODORIwagamamaLab presentation @MIT 20240509 IRODORI
wagamamaLab presentation @MIT 20240509 IRODORIIRODORI inc.
 
Future of Trade 2024 - Decoupled and Reconfigured - Snapshot Report
Future of Trade 2024 - Decoupled and Reconfigured - Snapshot ReportFuture of Trade 2024 - Decoupled and Reconfigured - Snapshot Report
Future of Trade 2024 - Decoupled and Reconfigured - Snapshot ReportDubai Multi Commodity Centre
 
Abortion pills in Muscut<Oman(+27737758557) Cytotec available.inn Kuwait City.
Abortion pills in Muscut<Oman(+27737758557) Cytotec available.inn Kuwait City.Abortion pills in Muscut<Oman(+27737758557) Cytotec available.inn Kuwait City.
Abortion pills in Muscut<Oman(+27737758557) Cytotec available.inn Kuwait City.daisycvs
 
一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样
一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样
一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样AS
 
hyundai capital 2023 consolidated financial statements
hyundai capital 2023 consolidated financial statementshyundai capital 2023 consolidated financial statements
hyundai capital 2023 consolidated financial statementsirhcs
 
Progress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdf
Progress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdfProgress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdf
Progress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdfHolger Mueller
 
Beyond Numbers A Holistic Approach to Forensic Accounting
Beyond Numbers A Holistic Approach to Forensic AccountingBeyond Numbers A Holistic Approach to Forensic Accounting
Beyond Numbers A Holistic Approach to Forensic AccountingYourLegal Accounting
 
Toyota Kata Coaching for Agile Teams & Transformations
Toyota Kata Coaching for Agile Teams & TransformationsToyota Kata Coaching for Agile Teams & Transformations
Toyota Kata Coaching for Agile Teams & TransformationsStefan Wolpers
 

Recently uploaded (20)

High Profile Bangalore Just VIP Brigade Road 100% Genuine at your Door Step
High Profile Bangalore Just VIP Brigade Road 100% Genuine at your Door StepHigh Profile Bangalore Just VIP Brigade Road 100% Genuine at your Door Step
High Profile Bangalore Just VIP Brigade Road 100% Genuine at your Door Step
 
stock price prediction using machine learning
stock price prediction using machine learningstock price prediction using machine learning
stock price prediction using machine learning
 
Creating an Income Statement with Forecasts: A Simple Guide and Free Excel Te...
Creating an Income Statement with Forecasts: A Simple Guide and Free Excel Te...Creating an Income Statement with Forecasts: A Simple Guide and Free Excel Te...
Creating an Income Statement with Forecasts: A Simple Guide and Free Excel Te...
 
How to refresh to be fit for the future world
How to refresh to be fit for the future worldHow to refresh to be fit for the future world
How to refresh to be fit for the future world
 
A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...
A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...
A BUSINESS PROPOSAL FOR SLAUGHTER HOUSE WASTE MANAGEMENT IN MYSORE MUNICIPAL ...
 
如何办理(SUT毕业证书)斯威本科技大学毕业证成绩单本科硕士学位证留信学历认证
如何办理(SUT毕业证书)斯威本科技大学毕业证成绩单本科硕士学位证留信学历认证如何办理(SUT毕业证书)斯威本科技大学毕业证成绩单本科硕士学位证留信学历认证
如何办理(SUT毕业证书)斯威本科技大学毕业证成绩单本科硕士学位证留信学历认证
 
First Time Home Buyer's Guide - KM Realty Group LLC
First Time Home Buyer's Guide - KM Realty Group LLCFirst Time Home Buyer's Guide - KM Realty Group LLC
First Time Home Buyer's Guide - KM Realty Group LLC
 
The Art of Decision-Making: Navigating Complexity and Uncertainty
The Art of Decision-Making: Navigating Complexity and UncertaintyThe Art of Decision-Making: Navigating Complexity and Uncertainty
The Art of Decision-Making: Navigating Complexity and Uncertainty
 
South Africa's 10 Most Influential CIOs to Watch.pdf
South Africa's 10 Most Influential CIOs to Watch.pdfSouth Africa's 10 Most Influential CIOs to Watch.pdf
South Africa's 10 Most Influential CIOs to Watch.pdf
 
WAM Corporate Presentation May 2024_w.pdf
WAM Corporate Presentation May 2024_w.pdfWAM Corporate Presentation May 2024_w.pdf
WAM Corporate Presentation May 2024_w.pdf
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 
tekAura | Desktop Procedure Template (2016)
tekAura | Desktop Procedure Template (2016)tekAura | Desktop Procedure Template (2016)
tekAura | Desktop Procedure Template (2016)
 
wagamamaLab presentation @MIT 20240509 IRODORI
wagamamaLab presentation @MIT 20240509 IRODORIwagamamaLab presentation @MIT 20240509 IRODORI
wagamamaLab presentation @MIT 20240509 IRODORI
 
Future of Trade 2024 - Decoupled and Reconfigured - Snapshot Report
Future of Trade 2024 - Decoupled and Reconfigured - Snapshot ReportFuture of Trade 2024 - Decoupled and Reconfigured - Snapshot Report
Future of Trade 2024 - Decoupled and Reconfigured - Snapshot Report
 
Abortion pills in Muscut<Oman(+27737758557) Cytotec available.inn Kuwait City.
Abortion pills in Muscut<Oman(+27737758557) Cytotec available.inn Kuwait City.Abortion pills in Muscut<Oman(+27737758557) Cytotec available.inn Kuwait City.
Abortion pills in Muscut<Oman(+27737758557) Cytotec available.inn Kuwait City.
 
一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样
一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样
一比一原版(USYD毕业证书)悉尼大学毕业证原件一模一样
 
hyundai capital 2023 consolidated financial statements
hyundai capital 2023 consolidated financial statementshyundai capital 2023 consolidated financial statements
hyundai capital 2023 consolidated financial statements
 
Progress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdf
Progress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdfProgress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdf
Progress Report - UKG Analyst Summit 2024 - A lot to do - Good Progress1-1.pdf
 
Beyond Numbers A Holistic Approach to Forensic Accounting
Beyond Numbers A Holistic Approach to Forensic AccountingBeyond Numbers A Holistic Approach to Forensic Accounting
Beyond Numbers A Holistic Approach to Forensic Accounting
 
Toyota Kata Coaching for Agile Teams & Transformations
Toyota Kata Coaching for Agile Teams & TransformationsToyota Kata Coaching for Agile Teams & Transformations
Toyota Kata Coaching for Agile Teams & Transformations
 

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