Ruby on Rails Guides(一)

准备工作

安装Ruby1.9.3或者更新
sudo apt-get install ruby-full
安装RubyGems
  1. 下载https://rubygems.org/pages/download#formats

  2. 解压

3.安装

ruby setup.rb
安装SQLite
  1. 下载 https://www.sqlite.org/download.html

  2. 安装 Sqlite
    下载源码进行编译

./configure
make
sudo make install
安装Rails
gem install rails

安装的时候出现了错误,Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://api.rubygems.org

是GFW的原因,重新配置源

gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/
gem sources -l
*** CURRENT SOURCES ***
https://ruby.taobao.org
# 请确保只有 ruby.taobao.org
gem install rails
创建第一个Blog程序
rails new blog

问题:一直卡在run bundle install
原因:运行这个的时候,会用默认的源。有两种方式:
rails new blog –skip-bundle 或者在run bundle install时按Ctrl-C终止;然后修改Gemfile里面的第一行,将source ‘https://rubygems.org’ 改为 source ‘http://ruby.taobao.org

改完source后,还需要运行bundle install

自动生成的目录说明:

├── app 
│   ├── assets
│   │   ├── images
│   │   ├── javascripts
│   │   │   └── application.js
│   │   └── stylesheets
│   │       └── application.css
│   ├── controllers
│   │   ├── application_controller.rb
│   │   └── concerns
│   ├── helpers
│   │   └── application_helper.rb
│   ├── mailers
│   ├── models
│   │   └── concerns
│   └── views
│       └── layouts
│           └── application.html.erb
├── bin
│   ├── bundle
│   ├── rails
│   ├── rake
│   └── setup
├── config
│   ├── application.rb
│   ├── boot.rb
│   ├── database.yml
│   ├── environment.rb
│   ├── environments
│   │   ├── development.rb
│   │   ├── production.rb
│   │   └── test.rb
│   ├── initializers
│   │   ├── assets.rb
│   │   ├── backtrace_silencers.rb
│   │   ├── cookies_serializer.rb
│   │   ├── filter_parameter_logging.rb
│   │   ├── inflections.rb
│   │   ├── mime_types.rb
│   │   ├── session_store.rb
│   │   └── wrap_parameters.rb
│   ├── locales
│   │   └── en.yml
│   ├── routes.rb
│   └── secrets.yml
├── config.ru
├── db
│   └── seeds.rb
├── Gemfile
├── Gemfile.lock
├── lib
│   ├── assets
│   └── tasks
├── log
├── public
│   ├── 404.html
│   ├── 422.html
│   ├── 500.html
│   ├── favicon.ico
│   └── robots.txt
├── Rakefile
├── README.rdoc
├── test
│   ├── controllers
│   ├── fixtures
│   ├── helpers
│   ├── integration
│   ├── mailers
│   ├── models
│   └── test_helper.rb
├── tmp
│   └── cache
│       └── assets
└── vendor
    └── assets
        ├── javascripts
        └── stylesheets

app/ 包括了 controllers, models, views, helpers, mailers and assets ,主要精力应该放在这个目录下。

bin/ 包括了启动app的脚本,也可以包括其他用于setup,deploy和run的脚本。

config/ 配置程序的 routes, database等等. 详细参照 Configuring Rails Applications.

config.ru Rack configuration for Rack based servers used to start the application.

db/ Contains your current database schema, as well as the database migrations.

Gemfile
Gemfile.lock These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the Bundler gem. For more information about Bundler, see the Bundler website.
lib/ 为你的程序扩展modules。

log/ 程序的log文件。

public/ 唯一的可以被外部看到的文件,包括了一些静态的文件和编译过的文件。

Rakefile 这个文件用于保存可以命令行运行的task。这些task被整个Rails组件定义。你应该增加自己的任务,通过添加新的文件到lib/tasks下面,而不是改变Rakefile。

README.rdoc 这是程序的简洁说明指南,你应该编辑这个文件告诉其他人你的程序是做什么的,怎么设置等等。

test/ Unit tests, fixtures, and other test apparatus. These are covered in Testing Rails Applications.

tmp/ 临时文件 (像 cache, pid, session files).

vendor/ 这个目录是放第三方的代码,一个标准的Rails程序,包括了vendored gems。

设置首页

访问 http://localhost:3000/welcome/index,可以看到刚才创建的View,但是如果希望把他改成首页。

编辑config/routes.rb

Rails.application.routes.draw do
  get 'welcome/index'

  # The priority is based upon order of creation:
  # first created -> highest priority.
  # See how all your routes lay out with "rake routes".
  #
  # You can have the root of your site routed with "root"
  # root 'welcome#index'
  #
  # ...

将其中的root ‘welcome#index’去掉注释。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值