Welcome to this VM! Your username is railsws
and your password (in case you need it, like when using sudo
) is railsws
as well.
Good luck and enjoy!
Here a list of the pre-installed software on this VM.
OS:
- Xubuntu (Ubuntu w/ XFCE desktop) 15.10
- Updates
- Install VirtualBox guest extensions
Shell:
- Prezto with many modules on
Editor:
Ruby (using rbenv):
Ruby on Rails:
- Simply by
gem install rails
- Followed by a
rbenv rehash
to make sure therails
command is available
Database:
- Installed the mighty Postgres database
- And pgAdmin
- A database user named
railsws
, with passwordrailsws
, andCREATEDB
permission is created
Heroku:
For the following steps you are expected to have account for Github and Heroku. If you do not have them, please register to both services: they are totally awesome!
Setup Git:
git config --global user.name "YOUR NAME"
git config --global user.email "[email protected]"
Setup your keypair for SSH (your keypair is encrypted so you are asked to provide a passphrase):
ssh-keygen -t rsa -C "[email protected]"
To setup Github, copy the output of this command:
cat ~/.ssh/id_rsa.pub
And paste it into the 'Add SSH key' for you find here (when logged in): https://github.com/settings/ssh
You can test it with the following command (answer yes
to "Are you sure you want to connect?"):
ssh -T [email protected]
Now setup supply your Heroku account credentials to your the Heroku toolbelt:
heroku login
There's a very basic application in ~/Projects/testapp
, merely serving as a proof that all works well.
You can change to the directory with cd ~/Projects/testapp
and then issue one of the following commands:
rails s # start the development server
rails c # open the console (CTRL-D to leave it)
rails db # open the database prompt (CTRL-D to quit)
rails generate --help # learn about stuff to generate
rake test # run the test suite
rake -T # list some common task you may run
rake routes # list the routes<->controllers mapping
Creating a new app called myapp
is simple:
rails new myapp -d postgresql
cd myapp
Since you are logged in to the OS as a user that has also exists as a CREATEDB
privileged Postgres database user, you should be able to connect to the database without specifying credentials. In case this does not work you should modify the config/database.yml
file to contain the correct database user and password (in our case both are railsws
).
Now create the database and start the server:
rake db:create
rails server
You can now point your browser (in this VM) to: http://localhost:3000
To create a new model --for example products
-- with an accompanying views and database 'migration' run:
rails generate scaffold products name:string description:text price:float stock:integer
rake db:migrate # create necessary table structure in the database
Using rails console
(or the shortcut rails c
) you can test drive your new model:
p = Product.new
p.name = "Lightsaber"
p.price = "98.85"
p.description = "You know you want it!"
p.stock = 42
p.save
Product.all
Learn Ruby:
- http://tryruby.org -- In-browser course
- https://www.codeschool.com/courses/try-ruby -- Same as above but with possibility to save your progress
- https://www.codecademy.com -- Basic introduction
- http://learnrubythehardway.org/book/index.html --Good book to get up to speed with Ruby
- http://docs.ruby-doc.com/docs/ProgrammingRuby -- Very popular book
Learn Ruby on Rails: