由于是1.8.x;圣经的1.9.3差太多,所以另外按1.8.X来创建hello world

第一個Hello World!!

1. 创建项目rails -d mysql first

2。创建控制器 

cd first

ruby script/generate controller hello

3.创建交互动作

vi app/controllers/hello_controller.rb 

修改为

class HelloController < ApplicationController

  def there

  end

end

4.创建对应动作的view层

vi app/views/hello/there.rhtml

<h1>Hello, World!</h1>

5.此时启动服务器

./script/server

5.前端访问

http://192.168.60.128:3000/hello/there

报错

Errno::ENOENT in HelloController#there

No such file or directory - /tmp/mysql.sock

解决: 安装mysql之后

  service mysqld start

解决办法:

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

遇到问题

#42000Unknown database 'first_development'

解决办法

[root@localhost /]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.1.52 Qihoo.com

 

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> create database first_development;

Query OK, 1 row affected (0.00 sec)

终于TMD访问成功

总结:

1.由于ruby on rails的架构,必须关联数据库,用 rails  first 创建会默认关联 sqlite库。去掉 database.yml也报错

2.用rails -d mysql first创建会在config/database.yml中写下

# MySQL.  Versions 4.1 and 5.0 are recommended.

#

# Install the MySQL driver:

#   gem install mysql

# On Mac OS X:

#   sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql

# On Mac OS X Leopard:

#   sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

#       This sets the ARCHFLAGS environment variable to your native architecture

# On Windows:

#   gem install mysql

#       Choose the win32 build.

#       Install MySQL and put its /bin directory on your path.

#

# And be sure to use new-style password hashing:

#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html

development:

  adapter: mysql

  encoding: utf8

  database: first_development

  username: root

  password:

  host: localhost

 

# Warning: The database defined as "test" will be erased and

# re-generated from your development database when you run "rake".

# Do not set this db to the same as development or production.

test:

  adapter: mysql

  encoding: utf8

  database: first_test

  username: root

  password:

  host: localhost

 

production:

  adapter: mysql

  encoding: utf8

  database: first_production

  username: root

  password: 

  host: localhost

说明当前开发时使用的是development库,上线后可以改用 production 库,具体怎么设置还没学习到

Ruby on Rails 實戰聖經阅读(三)的更多相关文章

  1. Ruby on Rails 實戰聖經阅读(二)

    1.操作系统 centos5.4 2.安装ruby yum install ruby 会安装得到 1.8.5 如果你公司用的是1.8.X就无所谓了, 拿这个学习就行了 如果你们公司用的是1.9.X,那 ...

  2. 如何从 0 开始学 ruby on rails (漫步版)

    如何从 0 开始学 ruby on rails (漫步版) ruby 是一门编程语言,ruby on rails 是 ruby 的一个 web 框架,简称 rails. 有很多人对  rails 感兴 ...

  3. 如何从 0 开始学 Ruby on Rails

    如何从 0 开始学 Ruby on Rails (漫步版)Ruby 是一门编程语言,Ruby on Rails 是 Ruby 的一个 web 框架,简称 Rails. 有很多人对 Rails 感兴趣, ...

  4. (转) 如何从 0 开始学 ruby on rails (漫步版)

    原文:http://readful.com/post/12322300571/0-ruby-on-rails ruby 是一门编程语言,ruby on rails 是 ruby 的一个 web 框架, ...

  5. 《Ruby on Rails教程》学习笔记

    本文是我在阅读 Ruby on Rails 教程的简体中文版时所做的摘录,以及学习时寻找的补充知识.补充知识主要来自于 Ruby on Rails 實戰聖經. Asset Pipeline 在最新版 ...

  6. [转]2010 Ruby on Rails 書單 與 練習作業

    原帖:http://wp.xdite.net/?p=1754 ========= 學習 Ruby on Rails 最快的途徑無非是直接使用 Rails 撰寫產品.而這個過程中若有 mentor 指導 ...

  7. ruby on rails on windows

    这次想系统学会rails,最终目标是将redmine改造成顺手的工具,主要的手段就是开发redmine插件.虽然网上都推荐使用类Unix系统,可手头只有win7系统,就安装了. 难免会遇到这样那样的问 ...

  8. 10个基于 Ruby on Rails 构建的顶级站点

    本文系国内 ITOM 行业领军企业 OneAPM 工程师翻译整理自 Raviraj Hegde 的文章 Top Sites Built with Ruby on Rails. 就其本身而言,Ruby ...

  9. Ruby on Rails创始人DHH谈如何进行混合移动APP开发

    混合型APP兼具原生型APP软件良好用户交互体验的优势和网页型APP软件跨平台开发的优势,并且其开发成本和网页型APP软件接近,其开发效率也远高于原生型APP软件.混合型APP已经被众多企业所认可.最 ...

随机推荐

  1. Android平台一些流行的使用3D技术开发的锁屏

    题外话:从2007年android系统的发布开始,到2008年的第一款手机问世,再到现在击败塞班,wm,黑霉,然后遍地开花,2013年,智能机出货超过了功能机,android功不可没.一路走来,虽然a ...

  2. db2 xml 转 table【XQuery系列】

    版本号:DB2 Version 9.1 1.创建測试表,初始化数据 create table emp (doc XML);   INSERT INTO EMP VALUES ('<dept bl ...

  3. 机器学习笔记(二)- from Andrew Ng的教学视频

    省略了Octave的使用方法结束,以后用得上再看吧 week three: Logistic Regression: 用于0-1分类 Hypothesis Representation: :Sigmo ...

  4. [Swust OJ 137]--波浪数(hash+波浪数构造)

    题目链接:http://acm.swust.edu.cn/problem/137/ Time limit(ms): 1000 Memory limit(kb): 65535   Description ...

  5. BZOJ 2242: [SDOI2011]计算器( 快速幂 + 扩展欧几里德 + BSGS )

    没什么好说的... --------------------------------------------------------------------- #include<cstdio&g ...

  6. Week2(9月19日):增加一个CodeFirst的例子来说明

    Part I:提问  =========================== 1.上堂课中我们使用了()数据库,它是()可部署的,只需要将相应的()文件添加到应用程序的()文件夹,就可以使用了,该数据 ...

  7. FineReport实现Java报表主题分析的效果图

    Java报表-財务主题-EVA经济附加 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYmVzdF9yZXBvcnQ=/font/5a6L5L2T/font ...

  8. POJ 3422 Kaka&#39;s Matrix Travels (最小费用最大流)

    POJ 3422 Kaka's Matrix Travels 链接:http://poj.org/problem? id=3422 题意:有一个N*N的方格,每一个方格里面有一个数字.如今卡卡要从左上 ...

  9. busybox 致命错误: curses.h:没有那个文件或文件夹

    $:~/dd/busybox-1.19.3$ make menuconfig   HOSTCC  scripts/basic/fixdep   HOSTCC  scripts/basic/split- ...

  10. android的事件分发机制理解

    android的事件分发机制理解 1.事件触发主要涉及到哪些层面的哪些函数(个人理解的顺序,可能在某一层会一次回调其它函数) activity中的dispatchTouchEvent .layout中 ...