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!
- 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.
- Create a new Rails project
- 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 >".
- 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.
- Generate Scaffold and Database structures
- 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.
- 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:

- Create the database tables by running "db:migrate" using
the similar steps described above - "Run Rake Task", "db", "migrate".
- Add and Configure jMaki widget
- 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:

- 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:

- 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.
- 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:

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

- 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
Posted
by Arun Gupta in web2.0 |

|

|

|

|

|
Posted by Arun Gupta's Blog on March 18, 2008 at 07:05 PM PDT #
Posted by Carla Mott's Blog on March 22, 2008 at 12:02 AM PDT #
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 #