You asked for styles, you got ‘em

December 9, 2007

I added stylebar support to cRazzed, using RJS, cookies, and Sass.

So far there’s “wacky”, “aqua”, and “hot pink”.

Maybe I’ll be able to add a live demo… although it’s quite insecure… maybe I’ll just post the sources.


cRazzed, my new Rails app

December 8, 2007

… as in you must be crazy to use this!

The idea behind this is like an information center where people post content, and that content could be anything from some Textile (RedCloth) to a Ruby Snippet formatted by CodeRay.

Here’s a screenshot:

Screenshot of cRazzed


Rails: How to get started

December 7, 2007

First step to rails… Installing it.

Okay, so, it’s much easier if you have RubyGems installed, and if you do:

[sudo] gem install -y rails

You can then start a project.


rails [--database=sqlite3] [options] [projectname]

You could read the README, but that’s complicated and this is a lot easier.
First of all, “cd” into your new project.

cd [projectname]

Models

Then, you can start with a Model.
In Rails, Models are like collections of objects. Behind them is a technology called ActiveRecord. Using this, we can…

  • create users… (script/generate model user name:string password:string about:string)

And other thing-a-ma-bobs.
IMPORTANT! Make sure you edit the db/migrate/[number]_create_[modelname].rb file first so that where it says create_table(…) there is a line like this right under it.

t.column :id, :integer, :null => false

Strangely, the generator doesn’t automatically put this in… I’ll have to file a bug report…

Rendering the information (a.k.a. Controllers)

Well, there is something called scaffolding which you could put in your app/controllers/[controllername]_controller.rb file… But I’m gonna teach you the hard , kind-of easy way.

First, the same way we generate a model:

script/generate controller [controllername]
# ...or...
script/generate scaffold [controllerandmodelname]

The app/controllers/[controllername]_controller.rb file should look like this

class [CamelCaseControllerName] < ApplicationController
layout "[layoutname]"
def [viewmethod]
[helping-hands]
end
#...
end

Views

I actually prefer using Haml rather than the usual RHTML, so go ahead and use RubyGems:

[sudo] gem install -y haml
#and
cd ..
haml --rails [projectname]
cd [projectname]

Great, your project is now Haml-enabled. What do I do now?

Fire up app/views/layouts/[layoutname].haml, and put in

!!!
%html
%head
%title= @title
%body
= yield

And, so, a beginning.

You may now delete everything in the public/ folder except the folders images/, stylesheets/, and javascripts/. After that:

script/server

Then fire up Firefox and go to:

http://localhost:3000/[controllername]/

Something should show if you configured everything correctly.


Follow

Get every new post delivered to your Inbox.