After unremitting efforts to finally put Ruby on Ralis development environment, in the WIN7 system, hurriedly to a most common example to practice practiced hand bar, feel the ruby ...
Again, my ruby-v is ruby-2.0.0p247. Gem-v is: 2.0.3. RAILS-V is: 4.0.0. It should be relatively new! So some commands may not be the same! First, create a new working directory! Mine is: D:\RubyWorkSpace.
Open Ruby's character command interface, go to working directory, new project Hello.
[Plain]View Plaincopyprint?
- Rails new Hello
In the old version of Rails Hello, new was introduced in this new version. Because of domestic reasons, the barrier of various walls, so that we may have problems in the new project. If it doesn't go wrong, your project will hear a line of code for the run bundle install after a series of create. Then there is no then, no matter how to wait for others just do not move. This time you need to add some parameters to the new project. As follows:
[Plain]View Plaincopyprint?
- Rails new Hello--skip-bundle
This tells rails to skip the bundle installation when creating a new project, and this time see the result, then go into the Hello project to open the Gemfile file, in the first line there is a: source ' https://rubygems.org/' Change to our domestic mirror source:
[Plain]View Plaincopyprint?
- SOURCE ' http://ruby.taobao.org/'
There is no problem installing bundles at this time:
[Plain]View Plaincopyprint?
- Gem Install bundle
You need to create a new controller: Say Specific action: Hello
[Plain]View Plaincopyprint?
- Rails Generate controller Say Hello
The previous version was built with Ruby Script/generate Controller, and after the build succeeds, go to \hello\app\controllers to open the Say_controller.rb file and see the following:
[Ruby]View Plaincopyprint?
- Class Saycontroller < Applicationcontroller
- def Hello
- End
- End
Go to: \hello\app\views\say Open edit: Hello.html.erb
[HTML]View Plaincopyprint?
- <H1> This is my first Ruby on Rails Web application! </H1>
- <p>hello world! </P>
Go to \hello\config Open: routes.rb We will see the route selection in the project:
[HTML]View Plaincopyprint?
- Get "Say/hello"
So we can access the controller through the Http://localhost:3000/say/hello to the page.
Other generated js,css files, and so on, not one to say
Start the server:
[Plain]View Plaincopyprint?
- Rails Server
Results from last run:
Special Note: If the page appears like this in Chinese, you need to save Hello.html.erb in UTF-8 format, or you will get an error.
[Script _ruby] first Ruby on Rails Web application HelloWorld