jMaki on Rails For DummiesCraig announced jMaki on Rails. Here I provide detailed steps to read data from a MySQL database and display it in a jMaki-wrapped Yahoo DataTable widget. 1. Download NetBeans 6.0 M9 (Full version) and configured to install only "Base IDE", "Java IDE", "Web and Java EE" and "Ruby" modules. A cutting-edge build can be obtained from the hudson build. 2. Download and install jMaki plug-in in NetBeans update center.
3. Create a new "Ruby on Rails Application" Project, lets say named 'jmaki_ror'.
script/plugin source http://jmaki-goodies.googlecode.com/svn/trunk/rails_plugins script/plugin install jmaki_core script/plugin install jmaki_yahoo The first step adds the plug-in registry to the list of registries used for searching plug-ins. The second two steps install the core and yahoo plug-ins.
<head> <%= stylesheet_link_tag "jmaki-standard", :media => "all" -%> <%= javascript_include_tag "jmaki" -%> <%= jmaki_setup -%> </head>
<%= @content_for_layout %>
layout "standard" 6. Configure the MySQL database
def self.up create_table :grids do |t| t.column :company, :string t.column :price, :float t.column :change, :float t.column :percent_change, :float t.column :last_updated, :string end end 4. Right-select NetBeans project, select 'Run Rake Target', 'db', 'migrate'. This generates the database table. Execute the following query to insert data into the table: insert into grids values (1, 'A Co', 71.72, 0.02, 0.03, 'Jan 1, 2007, 10:00am' ); insert into grids values (2, 'B Inc', 29.01, 0.42, 1.47, 'Feb 1, 2007, 10:00am' ); insert into grids values (3, 'C Group Inc', 83.81, 0.28, 0.34, 'Mar 1, 2007, 10:00am' ); insert into grids values (4, 'D Company', 52.55, 0.01, 0.02, 'Apr 1, 2007, 10:00am' ); 5. Add jMaki-wrapped Yahoo DataTable widget
Until the jMaki data model for grid and data widgets is consistent between Java and JRuby, you need to replace the generated code in 'yahoo.rhtml' with the following: <%= jmaki_widget 'yahoo.dataTable', :args => { :columns => [ { :title => 'Company', :width => 200, :locked => false }, { :title => 'Price', :width => 75, :renderer => 'usMoney' }, { :title => 'Change', :width => 75, :renderer => 'change' }, { :title => '% Change', :width => 75, :renderer => 'pctChange' }, { :title => 'Last Updated', :width => 85, :renderer => 'italic' } ] }, :value => @table_data -%>
def yahoo @table_data = [] Grid.find_all().each do |data| @table_data << [ data.company, data.price, data.change, data.percent_change, data.last_updated] end end 8. That's it, run your app and view the page at 'http://localhost:3000/jmaki/yahoo'. Now jMaki-wrapped Yahoo DataTable widget is picking data from the MySQL database. And as a next step, you can WAR'up this RoR application and deploy it on GlassFish V2 using these instructions. 日本語翻訳: Kana |