Linux‎ > ‎

Ruby & Rails

Clear Association Cache

posted May 12, 2017, 7:39 PM by Chris Martin   [ updated May 12, 2017, 7:40 PM ]

ActiveSupport::Dependencies::Reference.clear!

ActiveAdmin

posted Apr 9, 2016, 5:33 AM by Chris Martin

Time format and zone

To display time in the local time zone

#== TimeZone
config.prepend_before_action -> { Time.zone = "Sydney" }

Useful Stuff

posted Mar 5, 2015, 11:03 PM by Chris Martin   [ updated Mar 5, 2015, 11:08 PM ]

#include v #eager_load v #preload

Summary

eager_load generates one long query
preload generates two queries
include automatically decides to use either eager_load or preload

RoR (Ruby on Rails) primer

posted May 2, 2014, 6:55 PM by Chris Martin


To create a new rails project and populate with the required directories etc use

rail new <project name>

Install Gems required for a project that are specified in the Gemfile.
It is good practice to run this command when eve you go a git checkout or pull

bundle install

Update the database scheme
It is good practice to run this command when eve you go a git checkout or pull

rake db migrate







Install Ruby using ASDF

posted Dec 29, 2013, 7:48 PM by Chris Martin   [ updated Jul 21, 2022, 6:00 AM ]

Don't install the ruby packages supplied with your linux distro.  they are usually out of date
Instead, install via the RVM (Ruby Version manager). This will also allow you to install different versions and configurations for different projects.   The beautiful part of this is that it installs RVM and Ruby to our home directory, providing a sandboxed environment just for us.  

First update the app repository and install some prerequisites.
$ sudo apt-get update
$ sudo apt-get install build-essential openssl libreadline8 libreadline-dev curl git zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev libncurses-dev automake libtool bison subversion pkg-config curl gawk dirmngr gpg 

Now install ASDF
$ cd ~/
$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.2 # This installs ASDF via git

Edit the shell enviroments for next login
Add the following to ~/.bashrc:
. $HOME/.asdf/asdf.sh                # load the functions
. $HOME/.asdf/completions/asdf.bash  # load command compleations

reload our shell environment
$ . ~/.bashrc

Now that ASDF is installed we can Install Ruby
$ asdf plugin add ruby
$ asdf install ruby <version>

Now tell rvm that we want to use this version 
$ asdf local ruby <version>

Now that we have installed ASDF and a version of Ruby, we can install Rails. Because RVM is installed to our home directory, we don't need to use sudo to install things.  This will install the rails gem and the multitude of gems that it and its dependencies depend on, including Bundler.
$ gem install rails -v <version>

Install the Postgresql gem:
first make sure that postgresql is installed
$ sudo apt-get install postgresql

install the gem:  note the dependency on libpq-dev (for Ubuntu)
$ sudo apt-get install libpq-dev
$ gem install pg

Get a copy of the database and install it in to your own local database (see the posting on postgress backup and restore)

Next you can checkout the source using git (the separate post on setting up git).

To get all the gems loaded in your project change to the root directory of the application and run
bundle install

To run the application in a web server use
rails server
 




IDE's

posted Dec 29, 2013, 3:47 PM by Chris Martin   [ updated Jan 1, 2014, 5:34 AM ]

Standalone
JetBarins / RubyMine - http://www.jetbrains.com/ruby/
Aptana / Studio3 - http://aptana.com/products/studio3/download

Eclipse
Aptana / Studio3 / RadRails - http://aptana.com/products/studio3/download

1-6 of 6