Getting Started with Ruby/Rails [Resume]

The most difficult part of working on Ruby and rails is making it says “Hello World”. I’ll resume the very very unimaginable long previous post until you can say “hello world!” in your app. I do not know if you’ll have the same instruction, because I do not start Ruby by installing railsinstaller from railsinstaller.org, but you’ll get the same catch concept. So do not worry.

OBJECTION : “Hello World!” on rails

TODO :

  1. Install Ruby and friends.
  2. Configure them.

PRE-REQUISITE

  1. Know Ruby? Know the concept of PHP is just fine actually
  2. Know some PHP framework such as Kohana, Yii, or Codeigniter would be a great help

First thing first, these stuffs has to be installed nicely. These stuffs can be installed as one package with railsinstaller. You do not need to follow my steps. I just tell my story.

Ruby

Up to this date, it’s better if you use Ruby in version 1.9.x or higher. Mine? Ruby 1.9.3. Got if manually from here.

Gemfile

I install rubygem like apt-get in linux. I don’t know if you need it if you install it by railsinstaller. I use gemfile 1.8.x. I got it manually from here.

Rails

Install rails. I use gem to install rails.

gem install rails

Check your rails version by type this in your ruby-command-prompt

rails --version

Devkit

It’s for bundle ruby or rails… or something. I got it manually from here.

Connector MySQL-C

Because I do not use SQLite3. I need to configure some setting at Ruby so that it can works fine with my phpmyadmin (for mysql database). I got it from here. What you need is only the libmysql.dll. So Get the newest zip, download it, unzip it. Copy-paste the libmysql.dll to your folder C://your-ruby-folder/bin

-*****

Assume you installed all those stuffs nicely. Next step is start your web app rails. These many commands below you can type it in Start/Programs/your-ruby-folder/”Start command prompt with Ruby”

1. Create new rails app

rails new [your_rails_app_name] -d [database]

example :

rails new my_blog -d mysql

2. Before you can start your app, you NEED to enter into your app directory

cd my_blog

3. Start your app! After you type this command, you can acces your app in localhost:3000 by default. While you modify file you do not need to stop and restart rails.

rails server

or

rails s

4. Configure database. Automatically they generate database config for mysql if you type “-d mysql” before. You can modify it in db/database.yml

5. If you have not create db yet. You can do it easily with (it generates database as it configured at database.yml):

rake db:create

6. Start saying hello world! Rails provide us simple way to generate a pack of MVC. Let’s do this.

rails generate controller home index

It will generate some files. Controller home with function index. It also generate views for controller home.

7. Delete file index.html in folder public. Or you can type this command

rm public/index.html

8. Configure file routes.rb in folder config uncomment the following lines :

root :to => "home#index"

Well, check again your localhost:3000. It should works fine🙂

————-

Some FAQs

Ruby/gemfile/rails command can’t find its path?

Make sure that your ruby.exe, gemfile.exe, and rails.exe has been included in ENV_PATH

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s