首页 > 代码库 > Ruby on Rails 学习笔记 - 1 Hello World

Ruby on Rails 学习笔记 - 1 Hello World

原书地址:https://www.railstutorial.org/book/beginning

1. 使用cloud 9服务器

https://ide.c9.io

2. 创建一个workspace,进入以后安装rails:

gem install rails -v 4.2.0.beta4

3. 创建一个新的工程:

rails _4.2.0.beta4_ new hello_app

4. 修改Gemfile

source https://rubygems.orggem rails,                4.2.0.beta4gem sass-rails,           5.0.0.beta1gem uglifier,             2.5.3gem coffee-rails,         4.0.1gem jquery-rails,         4.0.0.beta2gem turbolinks,           2.3.0gem jbuilder,             2.2.3gem rails-html-sanitizer, 1.0.1gem sdoc,                 0.4.0, group: :docgroup :development, :test do  gem sqlite3,     1.3.9  gem byebug,      3.4.0  gem web-console, 2.0.0.beta3  gem spring,      1.1.3end

 

5. install bundle

bundle install

6. 启动服务器

在cloud9上面启动服务器的命令行:

rails server -b $IP -p $PORT

7. 修改app/controllers/application-controller.rb

class ApplicationController < ActionController::Base  # Prevent CSRF attacks by raising an exception.  # For APIs, you may want to use :null_session instead.  protect_from_forgery with: :exception    def hello    render text: "hello, world!"  end  end

 

8. config/routes.rb

代码如下:

Rails.application.routes.draw do  .  .  .  # You can have the root of your site routed with "root"  root application#hello  .  .  .end

 

Ruby on Rails 学习笔记 - 1 Hello World