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

No comments: