Ruby on Rails envy part 2 – The first webapplication

Fire up Putty and log on to our newish ROR virtual appliance!

Oh wait. First I have to think of something we are going to create. So how about a Marketplace app, where supply and demand meets? And since we’re so into a free society, let’s make it an app where no money is allowed. So we’re going to exchange goods and services. What do we need?

  • List all open requests
  • Create a new request
  • Read and display a request
  • Update the request
  • Delete the request

That will be enough for now. So, what are the features of the request?

  • name – name of the requester (string)
  • contents – the textbody of the request (text)
  • title – the title of the request (string)

Now start up Putty and log on to the BitNami server.

cd /opt/bitnami/projects
rails fleemarket

This is something like File -> New Project -> ASP.NET MVC 2 application in Visual Studio. With this command, you’ll create the complete web application in a folder ‘fleemarket’. If I cd into this new folder I get to see:
root@linux:/opt/bitnami/projects/fleemarket# ls
app db lib public README test vendor
config doc log Rakefile script tmp

Right, now let’s run it. After all, in VS I can also start debugging right after the creation of my project:

ruby script/server

Anyhow, we’ll get the following output as the server is starting. So we need to open up another instance of Putty for editing.

root@linux:/opt/bitnami/projects/fleemarket# ruby script/server
=> Booting Mongrel
=> Rails 2.3.5 application starting on
=> Call with -d to detach
=> Ctrl-C to shutdown server

So, let’s create the Request class first.

root@linux:/opt/bitnami/projects/fleemarket# ruby script/generate scaffold request requester:string title:string contents:string
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/requests
exists app/views/layouts/
exists test/functional/
exists test/unit/
create test/unit/helpers/
# etc

So, Rails created a controller and a view apparently. And now for the database.

root@linux:/opt/bitnami/projects/fleemarket# rake db:migrate
(in /opt/bitnami/projects/fleemarket)
== CreateRequests: migrating =================================================
— create_table(:requests)
-> 0.0040s
== CreateRequests: migrated (0.0042s) ========================================

I am done. And then check out what I’ve just created. A complete CRUD thing with a database.

Next time, let’s check out what just happened under da hood.

One Reply to “Ruby on Rails envy part 2 – The first webapplication”

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *

%d bloggers liken dit: