Project

reloj

0.0
No commit activity in last 3 years
No release in over 3 years
A lightewieght mvc framework inspired by Ruby on Rails. Try it out!
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 6.0
~> 0.10
~> 10.0
~> 3.3

Runtime

~> 0.18
~> 1.3
 Project Readme

Reloj

A lightweight web framework for creating database-backed web applications with the Model-View-Controller pattern. It features an active record pattern ORM, convenient methods for cookie storage for things like session tokens, convenient command line interface to speed up development (like reloj new name_of_app), and is designed to be easy to deploy. Check out a live app built with reloj and deployed on heroku

Getting Started

  1. Install Reloj at the command prompt if you haven't yet:

     gem install reloj
    
  2. At the command prompt, create a new Reloj application:

     reloj new myapp
    

    where "myapp" is the application name.

  3. Create a controller, a route, and a view (see below)

  4. Change directory to myapp and start the web server:

     cd myapp
     reloj server
    
  5. Using a browser, navigate to http://localhost:3000 and to see what you created.

Setting up the database

Reloj has some built in convenience features to make it easy to set up your database

To name your database, change the dbname value in config/db.yml. If you need to setup any other values for your local database (username, password, port), you can put them in the same file.

To create a database for your app to use, just run:

	bundle exec rake db:create

To destroy the database, run:

	bundle exec rake db:delete

To reset the database, run:

	bundle exec rake db:reset

Finally, to setup your schema and seed your database, use the db/setup.sql file. To run this file on the app's databasae, run:

	bundle exec rake db:setup

To learn how to manage the database when deploying, scroll down to the Deploy secction

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:

  1. Generate the sample app

     reloj generate:sample
    
  2. Move into the sample app directory

     cd reloj_sample
    
  3. run bundle install

  4. Set up the database

     bundle exec rake db:create
     bundle exec rake db:setup
    
  5. Run the server

     reloj server
    
  6. Navigate to localhost:3000

Deploying

Reloj is built to make deploying to heroku as easy as possible, here's how:

  1. Make sure there's a procfile in the project's root directory. The Procfile should contain the following line:

     web: bundle exec reloj server
    
  2. Commit your changes to git

     git commit -am "procfile"
    
  3. Create a new heroku app using the heroku cli

     heroku apps:create mynewapp
    
  4. Push your code to heroku (heroku apps:create should automatically add a remote repo to push to)

     git push heroku master
    
  5. Wait for the push to finish, then create your database tables and seed it as defined in db/setup.sql

     heroku run rake db:setup
    
  6. Wait for the rake task to finish, then open your app:

     heroku open
    

Enjoy your now-deployed app!

TODO