Reloj
A lightweight web framework for Ruby for creating database-backed web applications with the Model-View-Controller pattern.
Getting Started
Install Reloj at the command prompt if you haven't yet:
gem install relojAt the command prompt, create a new Reloj application:
reloj new myapp
where "myapp" is the application name.
Change directory to
myappand start the web server:cd myapp reloj serverUsing a browser, go to
http://localhost:3000and you'll see: "Welcome to Reloj!"
Models and ORM
Reloj uses the active record pattern for its object-relational mapping.
To use this functionality in your app, create a class for your model in app/models and have the model inherit from ModelBase
class Cat < ModelBase
# custom code goes here
finalize!
end
Some commands:
Cat.all
- Returns an array with instances of class Cat, one instance for each row in table cats
Cat.find(2)
- Finds the record in table cats with id 2, returns instance of Cat corresponding to that record
Controllers
Create controllers in app/controllers. Controllers should inherit from ControllerBase.
class CatsController < ControllerBase
def index
@cats = Cat.all
render :index
end
end
Routes
Write your routes in config/routes.rb
module App
ROUTES = Proc.new do
get '/cats', CatsController, :index
get '/cats/new', CatsController, :new
post '/cats', CatsController, :create
end
end
Running the sample app
Reloj includes a generator for a sample app. To check it out:
Generate the sample app
reloj generate:sampleMove into the sample app directory
cd reloj_sampleRun the server
reloj serverNavigate to localhost:3000