Miles to go ...

Arun Gupta is a Technology Evangelist for Web Services and Web 2.0 Apps at Sun. He was the spec lead for APIs in the Java platform, committer in multiple Open Source projects, participated in standard bodies and contributed to Java EE and SE releases.
« BitNami's JRubyStack... | Main | GlassFish v3 gem... »

http://blogs.sun.com/arungupta/date/20080312 Wednesday March 12, 2008

jMaki on Rails - Reloaded for NetBeans 6.1 beta & Rails 2.0


NetBeans 6.1 Beta was released last week. Amongst the many improvements, one of them is the bundled JRuby 1.1 RC2 and Rails 2.0.2. The jMaki plugin used to work fine with Rails 1.2.3 but need to be updated because of changed file name extensions for the default generated views (".rhtml.erb" instead of ".rhtml"). With this release of NetBeans, jMaki plugin has been updated to work in this configuration as well.

This blog provide detailed steps to install jMaki plugin, create a simple Rails 2.0 application using NetBeans IDE and update the generated scaffold to use a Yahoo Data Table widget for displaying the data. It is an update to screencast #web8, lets get started!

  1. Install the jMaki plugin - In NetBeans IDE, go to "Tools", "Plugins". Select "jMaki Ajax support" and click on "Install" button as shown in the following figure:



    Follow the instructions to install the plugin. The IDE is restarted after a successful install.
  2. Create a new Rails project
    1. Create a new Rails project by selecting "File", "New Project..." and selecting "Ruby" and "Ruby on Rails Application". Take all the defaults as shown below:


      and click on "Next >".
    2. Choose "Specify Database Information Directly" and specify the database configuration information as shown below:


      and click on "Finish". You need to make sure MySQL server is running.
  3. Generate Scaffold and Database structures
    1. Right-click on the newly created project, select "Generate..." and enter the values as shown below:


      and click on "OK". This creates a scaffold and model that would allow us to perform CRUD operations on Title, Author, ISBN and Description for a Book.
    2. Create the datbase by invoking db:create target. This is done by right-selecting the project, select "Run Rake Task", "db" and then "create" as shown below:


    3. Create the database tables by running "db:migrate" using the similar steps described above - "Run Rake Task", "db", "migrate".
  4. Add and Configure jMaki widget
    1. In the project, expand "Views", "books" and double-click on "index.rtml.erb" to edit it. This page is used to display all the books from the database table in an HTML table. It also shows links to perform CRUD operations on each book item. From the jMaki Yahoo palette, drag-and-drop a "Yahoo Data Table" right after "</table>" tag. The generated fragment looks like:



    2. The default generated code fragment shows 4 columns in the table. Lets add a new column to display the CRUD operations link. Add the following fragment:

      { :actions => 'Action', :id => 'actions' }

      right after

      { :label => 'Description', :id => 'description'}

      You also need to add a comma "," after the Descrption column fragment. The updated code looks like:

    3. Add the following Ruby fragment right before "<%= jmaki_widget" generated code:

      <%
      @rows_data = []
      for book in @books
        @rows_data << { :id => book.id,
          :title => book.title,
          :author => book.author,
          :isbn => book.isbn,
          :description => book.description,
          :actions => link_to('Show', book) + ' ' + link_to('Edit', edit_book_path(book)) + ' ' + link_to('Destroy', book, :confirm => 'Are you sure?', :method => :delete)
        }
      end
      %>


      This fragment creates a JSON array, @row_data, in the format expected by Yahoo Data Table widget, after retrieving the values from the database. 
    4. Finally, instead of reading the static values for columns, use the newly created "@row_data" to populate the values. The code with all the changes looks like as shown below:

  5. Run the project
    1. The scaffold is now accessible at http://localhost:3000/books. This page in the browser looks like:


    2. After adding couple of entries, the page looks like:

Previous entries that shows how jMaki can be used with Ruby-on-Rails in NetBeans IDE can seen here.

Technorati: netbeans jmaki jruby ruby rubyonrails mysql

del.icio.us | furl | simpy | slashdot | technorati | digg
Comments:

[Trackback] Ajax World East 2008 started earlier today. I delievered my "Web 2.0 Application development using jMaki" and the slides are available here. There were several demos shown in the talk (using NetBeans and GlassFish) and they are all accessible...

Posted by Arun Gupta's Blog on March 18, 2008 at 07:05 PM PDT #

[Trackback] There's a lot of new functionality in this release of jMaki. Performance enhancements, new widgets, upgrades to Yahoo 2.5 and Dojo 1.0.2, documentation and the new jMaki webtop are just some of what you will find.

Posted by Carla Mott's Blog on March 22, 2008 at 12:02 AM PDT #

[Trackback] As reported earlier, I presented on "Rails powered by GlassFish and jMaki" yesterday at The Server Side Java Symposium - Las Vegas. The slides are available here. The demos shown in the talk are available at: Rails 2.0 Scaffold...

Posted by Arun Gupta's Blog on March 27, 2008 at 01:40 PM PDT #

I have been pulling my hair out trying to figure out how to resize a doJo Grid in Rails.

No matter what I do it always defaults to a narrow width and only about 5 rows.

Anyone have any ideas

Posted by Edward Marshall on May 13, 2008 at 07:57 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
« BitNami's JRubyStack... | Main | GlassFish v3 gem... »

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.

--> ajax ajaxworld conf eclipse fitness gem glassfish glassfishday hyderabad india indigo interoperability javaone javaone2008 jax-ws jmaki jpa jruby marathon metro microsoft mysql netbeans phobos photography presos railsconf ruby rubyonrails running runninglog runsfm screencast siliconvalleymarathon sun suntechdays swdp tango theserverside totd training traveltips v3 vista wcf web2.0 webservices windows wsaddressing wsit
Project Tango: Adding Quality of Service and .NET Interoperability to the Metro Web Services Stack
Locations of visitors to this page

calendar

« May 2008
SunMonTueWedThuFriSat
    
11
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
       
Today

Stats

Today's Page Hits: 12158


Total # blog entries: 598
Total # comments: 1640

www.flickr.com
This is a Flickr badge showing public photos from ArunGupta. Make your own badge here.
Add to Technorati Favorites

Last 50