galatea-customize-fsm (customize-fsm-facemaker-1.0-beta) | 2009-09-22 16:59 |
galatea-dialog (galatea-dialog-20101115) | 2010-12-24 13:53 |
galatea-engine (galatea-engine-20090604) | 2009-10-05 10:58 |
galatea-ja-chaone (galatea-ja-chaone-1.3.2) | 2009-10-04 21:24 |
galatea-ja-unidic (galatea-ja-unidic-1.3.9) | 2009-10-05 11:14 |
galatea-linux-2002 (galatea-linux-ipa) | 2005-07-20 15:43 |
galatea-windows (galatea4win-2009-02) | 2009-10-05 13:36 |
galatea-windows-errata (chaone-win-1.3.2-091201) | 2009-12-01 13:32 |
We can realize application which controls Galatea by cooperating with framework of web application.
We can install Ruby on Rails which became Ubuntu package by the following procedure.
$ sudo apt-get install rails
We show example with Ruby on Rails 2.0.2 installed in gem.
$ which rails /var/lib/gems/1.8/bin/rails $ rails dialog create create app/controllers create app/helpers create app/models ... $ ./dialog/script/server => Booting WEBrick... => Rails application started on http://0.0.0.0:3000 => Ctrl-C to shutdown server; call with --help for options [2009-02-18 15:50:56] INFO WEBrick 1.3.1 [2009-02-18 15:50:56] INFO ruby 1.8.7 (2008-08-11) [i486-linux] [2009-02-18 15:50:56] INFO WEBrick::HTTPServer#start: pid=25026 port=3000
A screen of Rails is displayed when we open "http://localhost:3000/" with Mozilla Firefox.
Please stop script/server by pressing Ctrl-C.
We implement VoiceXML application of very simple Model-View-Controller cooperation.
At first we edit routes.rb so that View of the vxml format is referred to in a URL of the "http://server:port/model/index.vxml" format.
$ emacs dialog/config/routes.rb
ActionController::Routing::Routes.draw do |map| # .... map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' map.connect ':controller/:action.:format' # add this end
We make Model (database) by the name of product.
$ cd dialog $ ./script/generate model product name:string yomi:string price:integer exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/product.rb create test/unit/product_test.rb create test/fixtures/products.yml create db/migrate create db/migrate/001_create_products.rb
$ emacs test/fixtures/products.yml
p01: name: 玉子丼 yomi: たまごどん price: 550 p02: name: のり弁 yomi: のりべん price: 580 p03: name: おにぎりセット yomi: おにぎりせっと price: 600 p04: name: のりメンタイ yomi: のりめんたい price: 600
$ rake db:migrate (in /home/nishi/myprojct/dialog) == 1 CreateProducts: migrating ================================================ -- create_table(:products) -> 0.0052s == 1 CreateProducts: migrated (0.0053s) ======================================= $ rake db:fixtures:load
$ ./script/generate controller product exists app/controllers/ exists app/helpers/ create app/views/product exists test/functional/ create app/controllers/product_controller.rb create test/functional/product_controller_test.rb create app/helpers/product_helper.rb
$ emacs app/controllers/product_controller.rb
class ProductController < ApplicationController def index @products = Product.find(:all) end def show @product = Product.find(params[:id]) end end
$ emacs app/views/product/index.vxml.erb
<?xml version="1.0"?> <vxml version="2.0" xml:lang="ja"> <form id='main'> <block><log>商品リスト</log></block> <field name='id'> <prompt timeout='20s'> <% @products.each do |p| -%> <%=h p.name -%>、 <% end -%> </prompt> <grammar version='1.0' root='#product'> <rule id='product'> <one-of> <% @products.each do |p| -%> <item> <token sym="<%=h p.yomi %>" slot="id" value="<%=h p.id %>"> <%=h p.name %> </token> </item> <% end -%> <item> <token sym="まいくてすと">マイクテスト</token> </item> </one-of> </rule> </grammar> </field> <block> <submit next="<%= url_for(:action=>'show', :format=>'vxml') %>"/> </block> </form> </vxml>
$ emacs app/views/product/show.vxml.erb
<?xml version="1.0"?> <vxml version="2.0" xml:lang="ja"> <form id='main'> <block> <prompt> <%=h @product.name %>は<%=h @product.price %>円です。<break time="1s"/> </prompt> <goto next="<%= url_for(:action=>'index', :format=>'vxml') %>" /> </block> </form> </vxml>
The setup was done.
The runner of galatea has a option to start rails application.
$ cd .. $ ./script/runner --rails-server ./dialog http://localhost:3000/product/index.vxml