jMaki on Rails - Updated for NetBeans 6 M10
Based upon a
user request, this is a follow up entry to show how
jMaki
on Rails For Dummies work on
NetBeans 6
Milestone 10. Some of the steps are simplified and more details are
provided. The updates from the previous blog entry are
highlighted in this color.
- Download
NetBeans
6.0 M10 (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. - Download and install
href="https://ajax.dev.java.net/files/documents/3115/41646/org-netbeans-modules-sun-jmaki.nbm">jMaki
plug-in in NetBeans update center.- In NetBeans '
Tools', 'Plugins',
select 'Downloaded', click on '
'.Add
Plugins ... - Select the downloaded .NBM module, click on 'Install' button (bottom
left corner). Follow the next few instructions to install jMaki plug-in and restart the IDE. - To verify, go to '
Tools', 'Plugins',
select 'Installed'. It should show '
' with today's installation date.jMaki
Ajax support
- In NetBeans '
- Create a new "Ruby on Rails Application" Project, lets say named '
jmaki_ror'.
Take everything else as default. - Create a new controller by right-clicking the project,
select 'Generate ...', select 'controller',
specify the Name as 'jmaki' and Views as 'yahoo'. - jMaki-enable the Rails app
- Right click on your Rails project, select "Rails
Plugins ...". - Select the "Repositories" tab.
- Click "Add URL" and specify "
http://jmaki-goodies.googlecode.com/svn/trunk/rails_plugins".
This adds the plug-in registry to the list of repositories used for
searching plug-ins. - Now install the jmaki runtime. Select the "New
Plugins" tab . - Multi-select
jmaki_coreand
and press "Install". Follow the instructions and thejmaki_yahoo
two plug-ins will be installed. After the installation is complete,
you'll see the following:

and click on 'Close'. - Expand '
Views', right-click on
'layouts', select 'New', select
'RHTML file ...'.
Enter the 'File Name' as 'standard'.
This will add 'standard.rhtml' in layouts
sub-tree. Enter the following fragment before <body>:
<head><br>
<%= stylesheet_link_tag "jmaki-standard", :media
=> "all" -%><br>
<%= javascript_include_tag "jmaki" -%><br>
<%= jmaki_setup -%><br>
</head> - Within <body>, add the following fragment:
<%= @content_for_layout %> - In '
Controllers', 'jmaki_controller.rb',
add the following fragment before 'def yahoo'
line:
layout "standard"
- Right click on your Rails project, select "Rails
- Download and Configure the MySQL database
- Download
MySQL 5.0 Community Server
and install by taking all the default values. - In a command prompt window, Start MySQL
server using the command: 'mysqld-nt --user root'. - Create database using the command: '
'. You need to make sure that the databasemysqladmin -u root create
jmaki_ror_development
name in this script is changed to match the project name. - Right select the NetBeans project, select '
Generate',
select 'model', specify the arguments as 'grid',
click 'OK'. This will
generate, in NetBeans project, Database Migrations, migrate,
001_create_grids.rb. - Open
001_create_grids.rb,
changeself.up
helper
method such that it looks like:
def self.up<br>
create_table :grids do |t|<br>
t.column :company, :string<br>
t.column :price, :float<br>
t.column :change, :float<br>
t.column :percent_change, :float<br>
t.column :last_updated, :string<br>
end<br>
end - Right-select NetBeans project, select '
', 'Run
Rake
Targetdb', 'migrate'.
This generates the database
table. - Execute the query to insert data into the table.
- The easiest way to run this query is to run
mysql client in the command prompt window as: 'mysql --user root'.
- Enter the command as '
' to see the following interaction:use
jmaki_ror_development
mysql> use jmaki_ror_development;<br>
Database changed - And then execute the query given below:
insert into grids values (1, 'A Co', 71.72,
0.02, 0.03, 'Jan 1, 2007, 10:00am' );<br>insert into grids values (2, 'B Inc', 29.01, 0.42, 1.47, 'Feb 1, 2007,
10:00am' );<br>insert into grids values (3, 'C Group Inc', 83.81, 0.28, 0.34, 'Mar 1,
2007, 10:00am' );<br>insert into grids values (4, 'D Company', 52.55, 0.01, 0.02, 'Apr 1,
2007, 10:00am' );
- The easiest way to run this query is to run
- Download
- Add jMaki-wrapped Yahoo DataTable widget
- In NetBeans project, in '
Views',
'jmaki', 'yahoo.rhtml',
drag-and-drop 'Data Table' widget from the 'Yahoo'
category of jMaki palette.- 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',<br>
:args => {<br>
:columns => [<br>
{ :title => 'Company', :width => 200, :locked =>
false },<br>
{ :title => 'Price', :width => 75, :renderer =>
'usMoney' },<br>
{ :title => 'Change', :width => 75, :renderer =>
'change' },<br>
{ :title => '% Change', :width => 75, :renderer =>
'pctChange' },<br>
{ :title => 'Last Updated', :width => 85, :renderer
=> 'italic' }<br>
]<br>
},<br>
:value => @table_data<br>
-%> - '
@table_data' is defined
in 'jmaki_controller' in 'def yahoo'
as:
def yahoo<br>
@table_data = []<br>
Grid.find_all().each do |data|<br>
@table_data
<< [ data.company, data.price, data.change,
data.percent_change, data.last_updated]<br>
end<br>
end
- Until the jMaki data model for grid and data
- In NetBeans project, in '
- 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
href="http://blogs.sun.com/arungupta/entry/database_enabled_ror_war_on">these
instructions.
Technorati:
href="http://technorati.com/tag/jmaki">jmaki
href="http://technorati.com/tag/rubonrails">rubyonrails
ror
netbeans
mysql
glassfish
- Login or register to post comments
- Printer-friendly version
- arungupta's blog
- 1150 reads





