Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A quick how-to for Ruby On Rails

Rails How-to

Motivation

I'm learning rails, again, from scratch. I come from php and node environments.

Environment specs

I'm running a Vagrant machine with Ubuntu 14.04 64bits. In order to have the env ready for installing rails. We need to install some linux libraries. All the code that we will paste here are linux commands that must be executed in shell.

sudo apt-get update
sudo apt-get install build-essential

FAQ

Installing RVM

First, download RVM

Adding gpg key

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

Installing rvm

\curl -sSL https://get.rvm.io | bash

Source rvm to get changes in system

source ~/.rvm/scripts/rvm

Generate rvm docs, for the love of OSS <3

rvm docs generate

Installing Ruby

Installing ruby 1.9.3 (or can be any other version, your pick)

rvm install 1.9.3

Installing bundler

gem install bundler

Installing Rails and set it up to work.

Rails 3.2

gem install rails '3.2.8'

Creating a project

Create a new rails project in your chosed directory

cd /path/to/your/project/dir
rails new <project_name>

To make rails work with haml, open your Gemfile file and add these lines:

gem 'haml', '4.0.7'
gem 'haml-rails'

Now, open your onfig/application.rb file and add this within your class class Application < Rails::Application:

    # Using haml for generators
    config.generators do |g|
        g.template_engine :haml
    end

Follow this guide to learn about rails

Funny notes

In node, usually a webapp remains in memory, it is, once that you set the routes, the models and fire the webserver, this app will stay fixed until you restarted. So, if you change a model, you have to stop the app, and restart it to see changes.

By the other hand, in rails, apparently the webapp is separated from the routes, models, and views files. This means, that if you change a model, controller, or view, you only need to refresh your browser to see changes effectively.

This has goods and bads for both approaches. for example, in node, the bad is that since you have all in memmory, you're taking more space in memmory for a started app. and if you're in development mode, making changes, you'll have the hassle of restarting your app everytime. Here comes the handy use of tools like grunt-watch, which does this for you. In rails, tha bad is that, since the web browser has to read models, controllers and views for every request, every request is already slower than in a node app. the good thing, is that, when you're in development mode, you don't have to restart the app that much, hence the absence of tools like grunt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.