Feeds

Ruby runs on Rails with NetBeans

Build a web application in minutes

Choosing a cloud hosting partner with confidence

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

Remote control for virtualized desktops

More from The Register

next story
Be real, Apple: In-app goodie grab games AREN'T FREE – EU
Cupertino stands down after Euro legal threats
Download alert: Nearly ALL top 100 Android, iOS paid apps hacked
Attack of the Clones? Yeah, but much, much scarier – report
Microsoft: Your Linux Docker containers are now OURS to command
New tool lets admins wrangle Linux apps from Windows
Bada-Bing! Mozilla flips Firefox to YAHOO! for search
Microsoft system will be the default for browser in US until 2020
Facebook, working on Facebook at Work, works on Facebook. At Work
You don't want your cat or drunk pics at the office
Soz, web devs: Google snatches its Wallet off the table
Killing off web service in 3 months... but app-happy bonkers are fine
prev story

Whitepapers

Why cloud backup?
Combining the latest advancements in disk-based backup with secure, integrated, cloud technologies offer organizations fast and assured recovery of their critical enterprise data.
Forging a new future with identity relationship management
Learn about ForgeRock's next generation IRM platform and how it is designed to empower CEOS's and enterprises to engage with consumers.
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?
Protecting users from Firesheep and other Sidejacking attacks with SSL
Discussing the vulnerabilities inherent in Wi-Fi networks, and how using TLS/SSL for your entire site will assure security.
Saudi Petroleum chooses Tegile storage solution
A storage solution that addresses company growth and performance for business-critical applications of caseware archive and search along with other key operational systems.