Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reloj

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reloj

  • 0.1.10
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Reloj

A lightweight web framework for Ruby for creating database-backed web applications with the Model-View-Controller pattern. It features an ActiveRecord pattern ORM, convenient methods for cookie storage for things like session tokens, convenient executables to make development faster (like reloj new name_of_app), and is designed to be easy to deply. 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. Change directory to myapp and start the web server:

     cd myapp
     reloj server
    
  4. Using a browser, go to http://localhost:3000 and you'll see: "Welcome to Reloj!"

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 the server

     reloj server
    
  4. 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 with 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

FAQs

Package last updated on 12 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc