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
- Install Ruby and friends.
- Configure them.
- Know Ruby? Know the concept of PHP is just fine actually
- 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.
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.
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.
Install rails. I use gem to install rails.
gem install rails
Check your rails version by type this in your ruby-command-prompt
It’s for bundle ruby or rails… or something. I got it manually from here.
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]
rails new my_blog -d mysql
2. Before you can start your app, you NEED to enter into your app directory
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.
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):
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
8. Configure file routes.rb in folder config uncomment the following lines :
Well, check again your localhost:3000. It should works fine🙂
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