Friday 18 February 2011

New rails application with mysql

Following previous post I will create a new rails application with mysql as database server. (as before under ubuntu10.10)
First mysql dependencies:
user@Lap:~$ sudo apt-get install mysql-server libmysqlclient-dev

user@Lap:~$ gem install mysql2 --no-ri --no-rdoc
Building native extensions. This could take a while...
Successfully installed mysql2-0.2.6
1 gem installed

user@Lap:~$ rails new app -d mysql

this will create the directory app with all the necessary files


user@Lap:~$ cd app

create the database for the app (info for database in config/database.yml)
user@Lap:~$ rake db:create

user@Lap:~$ rails generate scaffold command execute:string
invoke active_record
create db/migrate/20110219000712_create_commands.rb
create app/models/command.rb
.........

user@Lap:~$ rake db:migrate
== CreateCommands: migrating =================================================
-- create_table(:commands)
-> 0.1622s
== CreateCommands: migrated (0.1624s) ========================================

user@Lap:~$ rm public/index.html

user@Lap:~$ nano config/routes.rb
# just remember to delete public/index.html.
root :to => "commands#index"
#note this is the new rails3 way to do it


user@Lap:~$ rails server


Reference: Video similar command examples with rails2


Install RVM and Ruby enterprise on ubuntu10.10

an quick way to install RVM the Ruby Version Manager:

user@Lap:~$ sudo aptitude install build-essential git-core curl

user@Lap:~$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
hoops.... this is not valid anymore, now:
user@Lap:~$ 
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)



From there you can install any version of ruby and different gemset.


Before using rvm command, you need to add this line to your .bashrc (at the end of the file)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Not any more! this is now included in the install(15/09/2011)

Then open new terminal type "rvm"


I like to use ruby enterprise (ree in short for rvm)
before to install ree let's install dependencies with the following command
user@Lap:~$ sudo aptitude install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev

Install ruby enterprise
user@Lap:~$ rvm install ree
Installing Ruby Enterprise Edition from source to: /home/user/.rvm/rubies/ree-1.8.7-2011.01
ree-1.8.7-2011.01 - #fetching (ruby-enterprise-1.8.7-2011.01)
....

use the install ree
user@Lap:~$ rvm use ree

then install the gem you want the usual way
user@Lap:~$ gem install name_of_gem
e.g
user@Lap:~$ gem install rails

Note: by default the gems are install in the global gemset but you are free to create different gemset with "rvm gemset create gemset_name"

Reference: RVM site