Feeds

Ruby runs on Rails with NetBeans

Build a web application in minutes

Security for virtualized datacentres

Next, we want to wire this up to a web page that allows us to add, edit and delete entries (which we'll refer to as posts) to this database. For that we need a Controller. Again, right click Linkshare, select Generate and this time use the drop-down menu to select Controller. Enter a value of Post for the Name field and then OK. This generates a Ruby file called post_controller.rb, which opens in the editor.

We add a single line of code to the skeleton so that it looks like this:


class PostController < ApplicationController
  scaffold :link
end

The final thing is to make sure that requests are routed to the correct place, so edit the routes.rb file (which is under the Configuration > Environments node of the Linkshare project tree). Adding the following line should route requests to the post controller:


map.connect ' ', :controller => "link"

With that in place, press F6 (or click on the big green Run Main Project button on the main tool bar) and launch the WEBrick web server with our Ruby on Rails application in place. Opening a browser and entering the URL http://localhost:3000/post will take us to a very basic looking web page that enables us to add, edit, list and delete posts.

Want to do more? Say, we decide to add a tags field so we have an idea what each URL is about. Easy. In the NetBeans Generator, menu select Migration, enter "new_tags_field" and then hit OK. This creates a new class called 002_new_tags_field.rb and opens the file in the editor. We'll make use of one of NetBeans keyboard triggers to make life simple for us. Enter a new line under def self.up, then enter mcol and then press the tab key. This expands to:


add_column :table, :column, :string

Change this to:

add_column :links, :tags, :string

Save the change, run the Migrate Database command to add a new tags field to the links table. Hit Refresh in the browser, click on the New Link button and, hey presto, there's a tags field as well.

It might not look like much, but we have the skeleton of a useful web application, created in just a few minutes. Enhancing the application with validations, adding new fields or functions (like voting buttons), or adding some better formatting can all be done with a few key strokes or mouse clicks.

It's why Ruby on Rails has made such a splash, and shows how well Ruby on Rails has been integrated into NetBeans.®

Beginner's guide to SSL certificates

More from The Register

next story
Microsoft on the Threshold of a new name for Windows next week
Rebranded OS reportedly set to be flung open by Redmond
Business is back, baby! Hasta la VISTA, Win 8... Oh, yeah, Windows 9
Forget touchscreen millennials, Microsoft goes for mouse crowd
SMASH the Bash bug! Apple and Red Hat scramble for patch batches
'Applying multiple security updates is extremely difficult'
Apple: SO sorry for the iOS 8.0.1 UPDATE BUNGLE HORROR
Apple kills 'upgrade'. Hey, Microsoft. You sure you want to be like these guys?
ARM gives Internet of Things a piece of its mind – the Cortex-M7
32-bit core packs some DSP for VIP IoT CPU LOL
Lotus Notes inventor Ozzie invents app to talk to people on your phone
Imagine that. Startup floats with voice collab app for Win iPhone
'Google is NOT the gatekeeper to the web, as some claim'
Plus: 'Pretty sure iOS 8.0.2 will just turn the iPhone into a fax machine'
prev story

Whitepapers

A strategic approach to identity relationship management
ForgeRock commissioned Forrester to evaluate companies’ IAM practices and requirements when it comes to customer-facing scenarios versus employee-facing ones.
Storage capacity and performance optimization at Mizuno USA
Mizuno USA turn to Tegile storage technology to solve both their SAN and backup issues.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?
Beginner's guide to SSL certificates
De-mystify the technology involved and give you the information you need to make the best decision when considering your online security options.
Security for virtualized datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.